Re: [PATCH 1/7] i2c: i2c-gpio: move header to platform_data

2018-05-14 Thread James Hogan
On Mon, May 14, 2018 at 11:37:20PM +0200, Wolfram Sang wrote:
> > diff --git a/arch/mips/alchemy/board-gpr.c b/arch/mips/alchemy/board-gpr.c
> > index 4e79dbd54a33..fa75d75b5ba9 100644
> > --- a/arch/mips/alchemy/board-gpr.c
> > +++ b/arch/mips/alchemy/board-gpr.c
> > @@ -29,7 +29,7 @@
> >  #include 
> >  #include 
> >  #include 
> > -#include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 

Acked-by: James Hogan <jho...@kernel.org>

Cheers
James


signature.asc
Description: PGP signature


[GIT PULL] Remove metag architecture

2018-02-27 Thread James Hogan
Hi Arnd,

On Fri, Feb 23, 2018 at 01:26:09PM +0100, Arnd Bergmann wrote:
> On Fri, Feb 23, 2018 at 12:02 PM, James Hogan <jho...@kernel.org> wrote:
> > I'm happy to put v2 in linux-next now (only patch 4 has changed, I just
> > sent an updated version), and send you a pull request early next week so
> > you can take it from there. The patches can't be directly applied with
> > git-am anyway thanks to the -D option to make them more concise.
> >
> > Sound okay?
> 
> Yes, sounds good, thanks!

As discussed, here is a tagged branch to remove arch/metag and dependent
drivers. Its basically v2 with some acks added.

Cheers
James

The following changes since commit 91ab883eb21325ad80f3473633f794c78ac87f51:

  Linux 4.16-rc2 (2018-02-18 17:29:42 -0800)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/jhogan/metag.git 
tags/metag_remove

for you to fetch changes up to ef9fb83815db7d7e03da9a0904b4ef352e633922:

  i2c: img-scb: Drop METAG dependency (2018-02-26 14:58:09 +)


Remove metag architecture

These patches remove the metag architecture and tightly dependent
drivers from the kernel. With the 4.16 kernel the ancient gcc 4.2.4
based metag toolchain we have been using is hitting compiler bugs, so
now seems a good time to drop it altogether.

--------
James Hogan (13):
  metag: Remove arch/metag/
  docs: Remove metag docs
  docs: Remove remaining references to metag
  Drop a bunch of metag references
  irqchip: Remove metag irqchip drivers
  clocksource: Remove metag generic timer driver
  tty: Remove metag DA TTY and console driver
  MAINTAINERS/CREDITS: Drop METAG ARCHITECTURE
  pinctrl: Drop TZ1090 drivers
  gpio: Drop TZ1090 drivers
  watchdog: imgpdc: Drop METAG dependency
  media: img-ir: Drop METAG dependency
  i2c: img-scb: Drop METAG dependency

 CREDITS|5 +
 Documentation/00-INDEX |2 -
 Documentation/admin-guide/kernel-parameters.txt|4 -
 Documentation/dev-tools/kmemleak.rst   |2 +-
 .../devicetree/bindings/gpio/gpio-tz1090-pdc.txt   |   45 -
 .../devicetree/bindings/gpio/gpio-tz1090.txt   |   88 -
 Documentation/devicetree/bindings/metag/meta.txt   |   30 -
 .../bindings/pinctrl/img,tz1090-pdc-pinctrl.txt|  127 --
 .../bindings/pinctrl/img,tz1090-pinctrl.txt|  227 ---
 .../features/core/BPF-JIT/arch-support.txt |1 -
 .../core/generic-idle-thread/arch-support.txt  |1 -
 .../features/core/jump-labels/arch-support.txt |1 -
 .../features/core/tracehook/arch-support.txt   |1 -
 .../features/debug/KASAN/arch-support.txt  |1 -
 .../debug/gcov-profile-all/arch-support.txt|1 -
 Documentation/features/debug/kgdb/arch-support.txt |1 -
 .../debug/kprobes-on-ftrace/arch-support.txt   |1 -
 .../features/debug/kprobes/arch-support.txt|1 -
 .../features/debug/kretprobes/arch-support.txt |1 -
 .../features/debug/optprobes/arch-support.txt  |1 -
 .../features/debug/stackprotector/arch-support.txt |1 -
 .../features/debug/uprobes/arch-support.txt|1 -
 .../debug/user-ret-profiler/arch-support.txt   |1 -
 .../features/io/dma-api-debug/arch-support.txt |1 -
 .../features/io/dma-contiguous/arch-support.txt|1 -
 .../features/io/sg-chain/arch-support.txt  |1 -
 .../features/lib/strncasecmp/arch-support.txt  |1 -
 .../locking/cmpxchg-local/arch-support.txt |1 -
 .../features/locking/lockdep/arch-support.txt  |1 -
 .../locking/queued-rwlocks/arch-support.txt|1 -
 .../locking/queued-spinlocks/arch-support.txt  |1 -
 .../locking/rwsem-optimized/arch-support.txt   |1 -
 .../features/perf/kprobes-event/arch-support.txt   |1 -
 .../features/perf/perf-regs/arch-support.txt   |1 -
 .../features/perf/perf-stackdump/arch-support.txt  |1 -
 .../sched/membarrier-sync-core/arch-support.txt|1 -
 .../features/sched/numa-balancing/arch-support.txt |1 -
 .../seccomp/seccomp-filter/arch-support.txt|1 -
 .../time/arch-tick-broadcast/arch-support.txt  |1 -
 .../features/time/clockevents/arch-support.txt |1 -
 .../time/context-tracking/arch-support.txt |1 -
 .../features/time/irq-time-acct/arch-support.txt   |1 -
 .../time/modern-timekeeping/arch-support.txt   |1 -
 .../features/time/virt-cpuacct/arch-support.txt|1 -
 .../features/vm/ELF-ASLR/arch-support.txt  |1 -
 .../features/vm/PG_uncached/arch-support.txt   |1 -
 Documentation/features/vm/THP/arch-support.txt |1 -
 Documentation/features/vm/TLB/arch-support.txt |1 -
 .../fe

Re: [PATCH 00/13] Remove metag architecture

2018-02-23 Thread James Hogan
On Fri, Feb 23, 2018 at 11:26:58AM +0100, Arnd Bergmann wrote:
> On Thu, Feb 22, 2018 at 12:38 AM, James Hogan <jho...@kernel.org> wrote:
> > So lets call it a day and drop the Meta architecture port from the
> > kernel. RIP Meta.
> 
> Since I brought up the architecture removal independently, I could
> pick this up into a git tree that also has the removal of some of the
> other architectures.
> 
> I see your tree is part of linux-next, so you could also just put it
> in there and send a pull request at the merge window if you prefer.
> 
> The only real reason I see for a shared git tree would be to avoid
> conflicts when we touch the same Kconfig files or #ifdefs in driver,
> but Meta only appears in
> 
> config FRAME_POINTER
> bool "Compile the kernel with frame pointers"
> depends on DEBUG_KERNEL && \
> (CRIS || M68K || FRV || UML || \
>  SUPERH || BLACKFIN || MN10300 || METAG) || \
> ARCH_WANT_FRAME_POINTERS
> 
> and
> 
> include/trace/events/mmflags.h:#elif defined(CONFIG_PARISC) ||
> defined(CONFIG_METAG) || defined(CONFIG_IA64)
> 
> so there is little risk.

I'm happy to put v2 in linux-next now (only patch 4 has changed, I just
sent an updated version), and send you a pull request early next week so
you can take it from there. The patches can't be directly applied with
git-am anyway thanks to the -D option to make them more concise.

Sound okay?

Thanks
James


signature.asc
Description: Digital signature


Re: [PATCH 00/13] Remove metag architecture

2018-02-22 Thread James Hogan
On Thu, Feb 22, 2018 at 10:26:54AM +0100, Peter Zijlstra wrote:
> On Wed, Feb 21, 2018 at 11:38:12PM +0000, James Hogan wrote:
> > So lets call it a day and drop the Meta architecture port from the
> > kernel. RIP Meta.
> 
> So long, and thanks for all the fish!
> 
> Nice cleanup though, most welcome :-)

I thought you might like it ;-)

> Acked-by: Peter Zijlstra (Intel) <pet...@infradead.org>

Thanks
James


signature.asc
Description: Digital signature


[PATCH 00/13] Remove metag architecture

2018-02-21 Thread James Hogan
These patches remove the metag architecture and tightly dependent
drivers from the kernel. With the 4.16 kernel the ancient gcc 4.2.4
based metag toolchain we have been using is hitting compiler bugs, so
now seems a good time to drop it altogether.

Quoting from patch 1:

The earliest Meta architecture port of Linux I have a record of was an
import of a Meta port of Linux v2.4.1 in February 2004, which was worked
on significantly over the next few years by Graham Whaley, Will Newton,
Matt Fleming, myself and others.

Eventually the port was merged into mainline in v3.9 in March 2013, not
long after Imagination Technologies bought MIPS Technologies and shifted
its CPU focus over to the MIPS architecture.

As a result, though the port was maintained for a while, kept on life
support for a while longer, and useful for testing a few specific
drivers for which I don't have ready access to the equivalent MIPS
hardware, it is now essentially dead with no users.

It is also stuck using an out-of-tree toolchain based on GCC 4.2.4 which
is no longer maintained, now struggles to build modern kernels due to
toolchain bugs, and doesn't itself build with a modern GCC. The latest
buildroot port is still using an old uClibc snapshot which is no longer
served, and the latest uClibc doesn't build with GCC 4.2.4.

So lets call it a day and drop the Meta architecture port from the
kernel. RIP Meta.

Cc: Guenter Roeck <li...@roeck-us.net>
Cc: Jonathan Corbet <cor...@lwn.net>
Cc: Steven Rostedt <rost...@goodmis.org>
Cc: Ingo Molnar <mi...@redhat.com>
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Arnaldo Carvalho de Melo <a...@kernel.org>
Cc: Alexander Shishkin <alexander.shish...@linux.intel.com>
Cc: Jiri Olsa <jo...@redhat.com>
Cc: Namhyung Kim <namhy...@kernel.org>
Cc: Thomas Gleixner <t...@linutronix.de>
Cc: Jason Cooper <ja...@lakedaemon.net>
Cc: Marc Zyngier <marc.zyng...@arm.com>
Cc: Daniel Lezcano <daniel.lezc...@linaro.org>
Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Cc: Jiri Slaby <jsl...@suse.com>
Cc: Linus Walleij <linus.wall...@linaro.org>
Cc: Wim Van Sebroeck <w...@linux-watchdog.org>
Cc: Mauro Carvalho Chehab <mche...@s-opensource.com>
Cc: Mauro Carvalho Chehab <mche...@kernel.org>
Cc: Wolfram Sang <w...@the-dreams.de>
Cc: linux-me...@vger.kernel.org
Cc: linux-...@vger.kernel.org
Cc: linux...@kvack.org
Cc: linux-g...@vger.kernel.org
Cc: linux-watch...@vger.kernel.org
Cc: linux-media@vger.kernel.org
Cc: linux-...@vger.kernel.org

James Hogan (13):
  metag: Remove arch/metag/
  docs: Remove metag docs
  docs: Remove remaining references to metag
  Drop a bunch of metag references
  irqchip: Remove metag irqchip drivers
  clocksource: Remove metag generic timer driver
  tty: Remove metag DA TTY and console driver
  MAINTAINERS/CREDITS: Drop METAG ARCHITECTURE
  pinctrl: Drop TZ1090 drivers
  gpio: Drop TZ1090 drivers
  watchdog: imgpdc: Drop METAG dependency
  media: img-ir: Drop METAG dependency
  i2c: img-scb: Drop METAG dependency

 CREDITS|5 +
 Documentation/00-INDEX |2 -
 Documentation/admin-guide/kernel-parameters.txt|4 -
 Documentation/dev-tools/kmemleak.rst   |2 +-
 .../devicetree/bindings/gpio/gpio-tz1090-pdc.txt   |   45 -
 .../devicetree/bindings/gpio/gpio-tz1090.txt   |   88 -
 Documentation/devicetree/bindings/metag/meta.txt   |   30 -
 .../bindings/pinctrl/img,tz1090-pdc-pinctrl.txt|  127 --
 .../bindings/pinctrl/img,tz1090-pinctrl.txt|  227 ---
 .../features/core/BPF-JIT/arch-support.txt |1 -
 .../core/generic-idle-thread/arch-support.txt  |1 -
 .../features/core/jump-labels/arch-support.txt |1 -
 .../features/core/tracehook/arch-support.txt   |1 -
 .../features/debug/KASAN/arch-support.txt  |1 -
 .../debug/gcov-profile-all/arch-support.txt|1 -
 Documentation/features/debug/kgdb/arch-support.txt |1 -
 .../debug/kprobes-on-ftrace/arch-support.txt   |1 -
 .../features/debug/kprobes/arch-support.txt|1 -
 .../features/debug/kretprobes/arch-support.txt |1 -
 .../features/debug/optprobes/arch-support.txt  |1 -
 .../features/debug/stackprotector/arch-support.txt |1 -
 .../features/debug/uprobes/arch-support.txt|1 -
 .../debug/user-ret-profiler/arch-support.txt   |1 -
 .../features/io/dma-api-debug/arch-support.txt |1 -
 .../features/io/dma-contiguous/arch-support.txt|1 -
 .../features/io/sg-chain/arch-support.txt  |1 -
 .../features/lib/strncasecmp/arch-support.txt  |1 -
 .../locking/cmpxchg-local/arch-support.txt |1 -
 .../features/locking/lockdep/arch-support.txt  |1 -
 .../locking/queued-rwlocks/arch-support.txt|1 -
 .../locking/queued-spinlocks/arch-support.txt 

[PATCH 12/13] media: img-ir: Drop METAG dependency

2018-02-21 Thread James Hogan
Now that arch/metag/ has been removed, remove the METAG dependency from
the IMG IR device driver. The hardware is also present on MIPS SoCs so
the driver still has value.

Signed-off-by: James Hogan <jho...@kernel.org>
Cc: Mauro Carvalho Chehab <mche...@s-opensource.com>
Cc: Mauro Carvalho Chehab <mche...@kernel.org>
Cc: linux-media@vger.kernel.org
Cc: linux-me...@vger.kernel.org
---
 drivers/media/rc/img-ir/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/rc/img-ir/Kconfig b/drivers/media/rc/img-ir/Kconfig
index a896d3c83a1c..d2c6617d468e 100644
--- a/drivers/media/rc/img-ir/Kconfig
+++ b/drivers/media/rc/img-ir/Kconfig
@@ -1,7 +1,7 @@
 config IR_IMG
tristate "ImgTec IR Decoder"
depends on RC_CORE
-   depends on METAG || MIPS || COMPILE_TEST
+   depends on MIPS || COMPILE_TEST
select IR_IMG_HW if !IR_IMG_RAW
help
   Say Y or M here if you want to use the ImgTec infrared decoder
-- 
2.13.6



Re: [PATCH 04/12] media: img-ir-hw: fix one kernel-doc comment

2017-11-29 Thread James Hogan
On Wed, Nov 29, 2017 at 05:46:25AM -0500, Mauro Carvalho Chehab wrote:
> Needed to suppress the following warnings:
>   drivers/media/rc/img-ir/img-ir-hw.c:351: warning: No description found 
> for parameter 'reg_timings'
>   drivers/media/rc/img-ir/img-ir-hw.c:351: warning: Excess function 
> parameter 'timings' description in 'img_ir_decoder_convert'
> 
> Signed-off-by: Mauro Carvalho Chehab <mche...@s-opensource.com>

Very true.
Acked-by: James Hogan <jho...@kernel.org>

Thanks
James

> ---
>  drivers/media/rc/img-ir/img-ir-hw.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
> b/drivers/media/rc/img-ir/img-ir-hw.c
> index f54bc5d23893..ec4ded84cd17 100644
> --- a/drivers/media/rc/img-ir/img-ir-hw.c
> +++ b/drivers/media/rc/img-ir/img-ir-hw.c
> @@ -339,7 +339,7 @@ static void img_ir_decoder_preprocess(struct 
> img_ir_decoder *decoder)
>  /**
>   * img_ir_decoder_convert() - Generate internal timings in decoder.
>   * @decoder: Decoder to be converted to internal timings.
> - * @timings: Timing register values.
> + * @reg_timings: Timing register values.
>   * @clock_hz:IR clock rate in Hz.
>   *
>   * Fills out the repeat timings and timing register values for a specific 
> clock
> -- 
> 2.14.3
> 


signature.asc
Description: Digital signature


Re: [PATCH v5 02/18] [media] img-ir: use new wakeup_protocols sysfs mechanism

2016-12-13 Thread James Hogan
Hi Sean,

On Tue, Dec 13, 2016 at 07:54:16AM +, Sean Young wrote:
> So that leaves the question open of whether we want to guess the protocol
> variant from the scancode for img-ir or if we can live with having to
> select this using wakeup_protocols. Having to do this does solve the issue
> of the driver guessing the wrong protocol if the higher bits happen to be
> 0 in the scancode.

I've received confirmation that pistachio doesn't yet support suspend in
mainline, in which case there can never be any real users of the old
semantics on current/old mainline kernel versions. So I'm fine with it
changing.

Cheers
James


signature.asc
Description: Digital signature


Re: [PATCH v5 02/18] [media] img-ir: use new wakeup_protocols sysfs mechanism

2016-12-12 Thread James Hogan
Hi Sean (and Sifan),

On Mon, Dec 12, 2016 at 09:13:43PM +, Sean Young wrote:
> Rather than guessing what variant a scancode is from its length,
> use the new wakeup_protocol.
> 
> Signed-off-by: Sean Young <s...@mess.org>
> Cc: James Hogan <james.ho...@imgtec.com>
> Cc: Sifan Naeem <sifan.na...@imgtec.com>
> ---
>  drivers/media/rc/img-ir/img-ir-hw.c|  2 +-
>  drivers/media/rc/img-ir/img-ir-hw.h|  2 +-
>  drivers/media/rc/img-ir/img-ir-jvc.c   |  2 +-
>  drivers/media/rc/img-ir/img-ir-nec.c   |  6 +++---
>  drivers/media/rc/img-ir/img-ir-rc5.c   |  2 +-
>  drivers/media/rc/img-ir/img-ir-rc6.c   |  2 +-
>  drivers/media/rc/img-ir/img-ir-sanyo.c |  2 +-
>  drivers/media/rc/img-ir/img-ir-sharp.c |  2 +-
>  drivers/media/rc/img-ir/img-ir-sony.c  | 11 +++
>  9 files changed, 13 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
> b/drivers/media/rc/img-ir/img-ir-hw.c
> index 1a0811d..841d9d7 100644
> --- a/drivers/media/rc/img-ir/img-ir-hw.c
> +++ b/drivers/media/rc/img-ir/img-ir-hw.c
> @@ -488,7 +488,7 @@ static int img_ir_set_filter(struct rc_dev *dev, enum 
> rc_filter_type type,
>   /* convert scancode filter to raw filter */
>   filter.minlen = 0;
>   filter.maxlen = ~0;
> - ret = hw->decoder->filter(sc_filter, , hw->enabled_protocols);
> + ret = hw->decoder->filter(sc_filter, , dev->wakeup_protocol);

According to patch 1, wakeup_protocol can always be set to
RC_TYPE_UNKNOWN using the protocol "none", but this function is used for
the normal filter too. AFAICT that would make it impossible to set a
normal filter without first setting the (new) wakeup protocol too.
Technically when type == RC_FILTER_NORMAL, the protocol should be based
on enabled_protocols, which should be set to a single protocol group.

I'll also note that enforcing that a wakeup protocol is set before
setting the wakeup filter (in patch 1 which I'm not Cc'd on) is an
incompatible API change. The old API basically meant that a mask of 0
disabled the wakeup filter, and there was no wakeup_protocol to set.

If wakeup filters can be changed to still be writable when wakeup
protocol is not set, then I suppose this driver could do something like:

if (type == RC_TYPE_NORMAL) {
use hw->enabled_protocols;
} else if (type == RC_TYPE_WAKEUP) {
if (dev->wakeup_protocol == RC_TYPE_UNKNOWN)
use hw->enabled_protocols;
else
use 1 << dev->wakeup_protocol;
}

Clearly allowing a wakeup filter with no protocol is not ideal though.

It probably isn't a big deal from the img-ir point of view for those
semantics to change slightly. The TZ1090 SoC I originally wrote the
driver for is practically obsolete from my point of view, and the common
clk and power management drivers to make this driver/feature functional
was never merged into mainline.

Sifan: Does the MIPS pistachio SoC support wake up using img-ir, and
does it even support suspend to RAM in mainline yet? If not then its
impossible to utilise the wake filters in current kernels and changing
the semantics is probably fine.

Cheers
James


>   if (ret)
>   goto unlock;
>   dev_dbg(priv->dev, "IR raw %sfilter=%016llx & %016llx\n",
> diff --git a/drivers/media/rc/img-ir/img-ir-hw.h 
> b/drivers/media/rc/img-ir/img-ir-hw.h
> index 91a2977..e1959ddc 100644
> --- a/drivers/media/rc/img-ir/img-ir-hw.h
> +++ b/drivers/media/rc/img-ir/img-ir-hw.h
> @@ -179,7 +179,7 @@ struct img_ir_decoder {
>   int (*scancode)(int len, u64 raw, u64 enabled_protocols,
>   struct img_ir_scancode_req *request);
>   int (*filter)(const struct rc_scancode_filter *in,
> -   struct img_ir_filter *out, u64 protocols);
> +   struct img_ir_filter *out, enum rc_type protocol);
>  };
>  
>  extern struct img_ir_decoder img_ir_nec;
> diff --git a/drivers/media/rc/img-ir/img-ir-jvc.c 
> b/drivers/media/rc/img-ir/img-ir-jvc.c
> index d3e2fc0..10b302c 100644
> --- a/drivers/media/rc/img-ir/img-ir-jvc.c
> +++ b/drivers/media/rc/img-ir/img-ir-jvc.c
> @@ -30,7 +30,7 @@ static int img_ir_jvc_scancode(int len, u64 raw, u64 
> enabled_protocols,
>  
>  /* Convert JVC scancode to JVC data filter */
>  static int img_ir_jvc_filter(const struct rc_scancode_filter *in,
> -  struct img_ir_filter *out, u64 protocols)
> +  struct img_ir_filter *out, enum rc_type protocol)
>  {
>   unsigned int cust, data;
>   unsigned int cust_m, data_m;
> diff --git a/drivers/media/rc/img-ir/img-ir-nec.c 
> b/drivers/media/rc/img-ir/img-ir-nec.c
> index

Re: Build regressions/improvements in v4.5-rc7

2016-03-08 Thread James Hogan
Hi,

On Mon, Mar 07, 2016 at 10:01:09AM +0100, Geert Uytterhoeven wrote:
> On Mon, Mar 7, 2016 at 9:55 AM, Geert Uytterhoeven  
> wrote:
> > JFYI, when comparing v4.5-rc7[1] to v4.5-rc6[3], the summaries are:
> >   - build errors: +8/-7
>   + error: debugfs.c: undefined reference to `clk_round_rate':  =>
> .text+0x11b9e0)
> 
> arm-randconfig
> 
> While looking for more context, I noticed another regression that fell through
> the cracks of my script:
> 
> arch/arm/kernel/head.o: In function `stext':
> (.head.text+0x40): undefined reference to `CONFIG_PHYS_OFFSET'
> drivers/built-in.o: In function `v4l2_clk_set_rate':
> debugfs.c:(.text+0x11b9e0): undefined reference to `clk_round_rate'
> 
>   + error: misc.c: undefined reference to `ftrace_likely_update':  =>
> .text+0x714), .text+0x94c), .text+0x3b8), .text+0xc10)
> 
> sh-randconfig
> 
> arch/sh/boot/compressed/misc.o: In function `lzo1x_decompress_safe':
> misc.c:(.text+0x3b8): undefined reference to `ftrace_likely_update'
> misc.c:(.text+0x714): undefined reference to `ftrace_likely_update'
> misc.c:(.text+0x94c): undefined reference to `ftrace_likely_update'
> arch/sh/boot/compressed/misc.o: In function `unlzo.constprop.2':
> misc.c:(.text+0xc10): undefined reference to `ftrace_likely_update'
> 
>   + /tmp/cc52LvuK.s: Error: can't resolve `_start' {*UND* section} -
> `L0^A' {.text section}:  => 41, 403
>   + /tmp/ccHfoDA4.s: Error: can't resolve `_start' {*UND* section} -
> `L0^A' {.text section}:  => 43
>   + /tmp/cch1r0UQ.s: Error: can't resolve `_start' {*UND* section} -
> `L0^A' {.text section}:  => 49, 378
>   + /tmp/ccoHdFI8.s: Error: can't resolve `_start' {*UND* section} -
> `L0^A' {.text section}:  => 43
> 
> mips-allnoconfig
> bigsur_defconfig
> malta_defconfig
> cavium_octeon_defconfig
> 
> Not really new, but it would be great if the MIPS people could get this
> fixed for the final release.

This would appear to be related to the ld version check for VDSO
failing.

awk: /home/kisskb/slave/src/scripts/ld-version.sh: line 4: regular expression 
compile failed (missing '(')
.*)
/bin/sh: 1: [: -lt: unexpected operator

I.e. this line:
gsub(".*)", "");

appears to be trying to turn e.g. "GNU ld (Gentoo 2.25.1 p1.1) 2.25.1"
into " 2.25.1", so perhaps the bracket should be escaped. What version
of awk is it using? (GNU Awk 4.0.2 works for me).

Can somebody experiencing this please try:
${CROSS_COMPILE}ld --version | ./scripts/ld-version.sh

with the following patch, to see if it helps.

Thanks
James

diff --git a/scripts/ld-version.sh b/scripts/ld-version.sh
index 198580d245e0..1659b409ef10 100755
--- a/scripts/ld-version.sh
+++ b/scripts/ld-version.sh
@@ -1,7 +1,7 @@
 #!/usr/bin/awk -f
 # extract linker version number from stdin and turn into single number
{
-   gsub(".*)", "");
+   gsub(".*\\)", "");
split($1,a, ".");
print a[1]*1000 + a[2]*10 + a[3]*1 + a[4]*100 + a[5];
exit


signature.asc
Description: Digital signature


Re: [PATCH] rc: img-ir: fix error in parameters passed to irq_free()

2015-02-10 Thread James Hogan
On Tue, Feb 10, 2015 at 10:41:56AM +, Sifan Naeem wrote:
 img_ir_remove() passes a pointer to the ISR function as the 2nd
 parameter to irq_free() instead of a pointer to the device data
 structure.
 This issue causes unloading img-ir module to fail with the below
 warning after building and loading img-ir as a module.
 
 WARNING: CPU: 2 PID: 155 at ../kernel/irq/manage.c:1278
 __free_irq+0xb4/0x214() Trying to free already-free IRQ 58
 Modules linked in: img_ir(-)
 CPU: 2 PID: 155 Comm: rmmod Not tainted 3.14.0 #55 ...
 Call Trace:
 ...
 [8048d420] __free_irq+0xb4/0x214
 [8048d6b4] free_irq+0xac/0xf4
 [c009b130] img_ir_remove+0x54/0xd4 [img_ir] [8073ded0]
 platform_drv_remove+0x30/0x54 ...
 
 Signed-off-by: Sifan Naeem sifan.na...@imgtec.com
 Fixes: 160a8f8aec4d ([media] rc: img-ir: add base driver)
 Cc: sta...@vger.kernel.org # 3.15+

Thanks for catching this Sifan. It appears to have been introduced while
getting the driver ready for upstream (it used to use the devm_* API to
request the IRQ, but I changed it to avoid the ISR racing with module
removal).

Acked-by: James Hogan james.ho...@imgtec.com

Cheers
James

 ---
  drivers/media/rc/img-ir/img-ir-core.c |2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
 
 diff --git a/drivers/media/rc/img-ir/img-ir-core.c 
 b/drivers/media/rc/img-ir/img-ir-core.c
 index 77c78de..7020659 100644
 --- a/drivers/media/rc/img-ir/img-ir-core.c
 +++ b/drivers/media/rc/img-ir/img-ir-core.c
 @@ -146,7 +146,7 @@ static int img_ir_remove(struct platform_device *pdev)
  {
   struct img_ir_priv *priv = platform_get_drvdata(pdev);
  
 - free_irq(priv-irq, img_ir_isr);
 + free_irq(priv-irq, priv);
   img_ir_remove_hw(priv);
   img_ir_remove_raw(priv);
  
 -- 
 1.7.9.5
 


signature.asc
Description: Digital signature


Re: [PATCH v2] rc: img-ir: Add and enable sys clock for img-ir

2015-02-04 Thread James Hogan
On 04/02/15 16:48, Sifan Naeem wrote:
 Gets a handle to the system clock, already described in the binding
 document, and calls the appropriate common clock framework functions
 to mark it prepared/enabled, the common clock framework initially
 enables the clock and doesn't disable it at least until the
 device/driver is removed.
 It's important the systen clock is enabled before register interface is
 accessed by the driver.
 The system clock to IR is needed for the driver to communicate with the
 IR hardware via MMIO accesses on the system bus, so it must not be
 disabled during use or the driver will malfunction.
 
 Signed-off-by: Sifan Naeem sifan.na...@imgtec.com

Thanks Sifan, looks good to me, doesn't break tz1090, and seems to still
cope with no clocks provided in DT.

Acked-by: James Hogan james.ho...@imgtec.com

Cheers
James

 ---
 Changes from v1:
 System clock enabled in probe function before any hardware is accessed.
 Error handling in probe function ensures ISR doesn't get called with 
 system clock disabled.
 
  drivers/media/rc/img-ir/img-ir-core.c |   29 +
  drivers/media/rc/img-ir/img-ir.h  |2 ++
  2 files changed, 27 insertions(+), 4 deletions(-)
 
 diff --git a/drivers/media/rc/img-ir/img-ir-core.c 
 b/drivers/media/rc/img-ir/img-ir-core.c
 index 77c78de..a10d666 100644
 --- a/drivers/media/rc/img-ir/img-ir-core.c
 +++ b/drivers/media/rc/img-ir/img-ir-core.c
 @@ -110,16 +110,32 @@ static int img_ir_probe(struct platform_device *pdev)
   priv-clk = devm_clk_get(pdev-dev, core);
   if (IS_ERR(priv-clk))
   dev_warn(pdev-dev, cannot get core clock resource\n);
 +
 + /* Get sys clock */
 + priv-sys_clk = devm_clk_get(pdev-dev, sys);
 + if (IS_ERR(priv-sys_clk))
 + dev_warn(pdev-dev, cannot get sys clock resource\n);
   /*
 -  * The driver doesn't need to know about the system (sys) or power
 -  * modulation (mod) clocks yet
 +  * Enabling the system clock before the register interface is
 +  * accessed. ISR shouldn't get called with Sys Clock disabled,
 +  * hence exiting probe with an error.
*/
 + if (!IS_ERR(priv-sys_clk)) {
 + error = clk_prepare_enable(priv-sys_clk);
 + if (error) {
 + dev_err(pdev-dev, cannot enable sys clock\n);
 + return error;
 + }
 + }
  
   /* Set up raw  hw decoder */
   error = img_ir_probe_raw(priv);
   error2 = img_ir_probe_hw(priv);
 - if (error  error2)
 - return (error == -ENODEV) ? error2 : error;
 + if (error  error2) {
 + if (error == -ENODEV)
 + error = error2;
 + goto err_probe;
 + }
  
   /* Get the IRQ */
   priv-irq = irq;
 @@ -139,6 +155,9 @@ static int img_ir_probe(struct platform_device *pdev)
  err_irq:
   img_ir_remove_hw(priv);
   img_ir_remove_raw(priv);
 +err_probe:
 + if (!IS_ERR(priv-sys_clk))
 + clk_disable_unprepare(priv-sys_clk);
   return error;
  }
  
 @@ -152,6 +171,8 @@ static int img_ir_remove(struct platform_device *pdev)
  
   if (!IS_ERR(priv-clk))
   clk_disable_unprepare(priv-clk);
 + if (!IS_ERR(priv-sys_clk))
 + clk_disable_unprepare(priv-sys_clk);
   return 0;
  }
  
 diff --git a/drivers/media/rc/img-ir/img-ir.h 
 b/drivers/media/rc/img-ir/img-ir.h
 index 2ddf560..f1387c0 100644
 --- a/drivers/media/rc/img-ir/img-ir.h
 +++ b/drivers/media/rc/img-ir/img-ir.h
 @@ -138,6 +138,7 @@ struct clk;
   * @dev: Platform device.
   * @irq: IRQ number.
   * @clk: Input clock.
 + * @sys_clk: System clock.
   * @reg_base:Iomem base address of IR register block.
   * @lock:Protects IR registers and variables in this struct.
   * @raw: Driver data for raw decoder.
 @@ -147,6 +148,7 @@ struct img_ir_priv {
   struct device   *dev;
   int irq;
   struct clk  *clk;
 + struct clk  *sys_clk;
   void __iomem*reg_base;
   spinlock_t  lock;
  
 



signature.asc
Description: OpenPGP digital signature


Re: [PATCH] rc: img-ir: Add and enable sys clock for IR

2015-02-04 Thread James Hogan
Hi Sifan,

On 03/02/15 17:30, Sifan Naeem wrote:
 Gets a handle to the system clock, already described in the binding
 document, and calls the appropriate common clock
 framework functions to mark it prepared/enabled, the common clock
 framework initially enables the clock and doesn't disable it at least
 until the device/driver is removed.
 The system clock to IR is needed for the driver to communicate with the
 IR hardware via MMIO accesses on the system bus, so it must not be
 disabled during use or the driver will malfunction.
 
 Signed-off-by: Sifan Naeem sifan.na...@imgtec.com
 ---
  drivers/media/rc/img-ir/img-ir-core.c |   13 +
  drivers/media/rc/img-ir/img-ir.h  |2 ++
  2 files changed, 11 insertions(+), 4 deletions(-)
 
 diff --git a/drivers/media/rc/img-ir/img-ir-core.c 
 b/drivers/media/rc/img-ir/img-ir-core.c
 index 77c78de..783dd21 100644
 --- a/drivers/media/rc/img-ir/img-ir-core.c
 +++ b/drivers/media/rc/img-ir/img-ir-core.c
 @@ -60,6 +60,8 @@ static void img_ir_setup(struct img_ir_priv *priv)
  
   if (!IS_ERR(priv-clk))
   clk_prepare_enable(priv-clk);
 + if (!IS_ERR(priv-sys_clk))
 + clk_prepare_enable(priv-sys_clk);

The patch mostly looks good, however I just realised this only enables
the system clock after it has already used the register interface. To be
safe it should really be enabled before any hardware accesses, so before
img_ir_ident() is called (and certainly before the img_ir_setup_raw()
and img_ir_setup_hw() functions are called since they set up the default
timings / irq mask etc).

Currently img_ir_probe_raw() and img_ir_probe_hw() don't appear to
access the hardware, but I can imagine they may want to access hardware
in future to read the revision register, so I think its worth doing it
from img_ir_probe() before they get called too, which should also ensure
the ISR doesn't get called with sysclock disabled (obviously error
handling in probe function would need to take it into account).

I suspect you would see this causing a problem when the driver is built
as a module and loaded after unused clocks have been automatically
disabled by the common clock framework at the end of the init sequence.

Thanks
James

  }
  
  static void img_ir_ident(struct img_ir_priv *priv)
 @@ -110,10 +112,11 @@ static int img_ir_probe(struct platform_device *pdev)
   priv-clk = devm_clk_get(pdev-dev, core);
   if (IS_ERR(priv-clk))
   dev_warn(pdev-dev, cannot get core clock resource\n);
 - /*
 -  * The driver doesn't need to know about the system (sys) or power
 -  * modulation (mod) clocks yet
 -  */
 +
 + /* Get sys clock */
 + priv-sys_clk = devm_clk_get(pdev-dev, sys);
 + if (IS_ERR(priv-sys_clk))
 + dev_warn(pdev-dev, cannot get sys clock resource\n);
  
   /* Set up raw  hw decoder */
   error = img_ir_probe_raw(priv);
 @@ -152,6 +155,8 @@ static int img_ir_remove(struct platform_device *pdev)
  
   if (!IS_ERR(priv-clk))
   clk_disable_unprepare(priv-clk);
 + if (!IS_ERR(priv-sys_clk))
 + clk_disable_unprepare(priv-sys_clk);
   return 0;
  }
  
 diff --git a/drivers/media/rc/img-ir/img-ir.h 
 b/drivers/media/rc/img-ir/img-ir.h
 index 2ddf560..f1387c0 100644
 --- a/drivers/media/rc/img-ir/img-ir.h
 +++ b/drivers/media/rc/img-ir/img-ir.h
 @@ -138,6 +138,7 @@ struct clk;
   * @dev: Platform device.
   * @irq: IRQ number.
   * @clk: Input clock.
 + * @sys_clk: System clock.
   * @reg_base:Iomem base address of IR register block.
   * @lock:Protects IR registers and variables in this struct.
   * @raw: Driver data for raw decoder.
 @@ -147,6 +148,7 @@ struct img_ir_priv {
   struct device   *dev;
   int irq;
   struct clk  *clk;
 + struct clk  *sys_clk;
   void __iomem*reg_base;
   spinlock_t  lock;
  
 



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 3/5] rc: img-ir: biphase enabled with workaround

2014-12-12 Thread James Hogan
Hi Sifan,

On 11/12/14 18:54, Sifan Naeem wrote:
 +/*
 + * Timer function to re-enable the current protocol after it had been
 + * cleared when invalid interrupts were generated due to a quirk in
 +the
 + * img-ir decoder.
 + */
 +static void img_ir_suspend_timer(unsigned long arg) {
 +   struct img_ir_priv *priv = (struct img_ir_priv *)arg;
 +
 +   img_ir_write(priv, IMG_IR_IRQ_CLEAR,
 +   IMG_IR_IRQ_ALL  ~IMG_IR_IRQ_EDGE);
 +
 +   /* Don't set IRQ if it has changed in a different context. */

 Should you even be clearing IRQs in that case? Maybe safer to just treat that
 case as a return immediately without touching anything sort of situation.

 don't have to clear it for this work around to work, so will remove.
 
 +   if ((priv-hw.suspend_irqen  IMG_IR_IRQ_EDGE) ==
 +   img_ir_read(priv, IMG_IR_IRQ_ENABLE))
 +   img_ir_write(priv, IMG_IR_IRQ_ENABLE, priv-
 hw.suspend_irqen);
 +   /* enable */
 +   img_ir_write(priv, IMG_IR_CONTROL, priv-hw.reg_timings.ctrl); }

To clarify, I was only referring to the case where the irq mask has
changed unexpectedly. If it hasn't changed then it would seem to make
sense to clear pending interrupts (i.e. the ones we've been
intentionally ignoring) before re-enabling them.

When you say it works without, do you mean there never are pending
interrupts (if you don't press any other buttons on the remote)?

Cheers
James



signature.asc
Description: OpenPGP digital signature


Re: [PATCH v2 3/5] rc: img-ir: biphase enabled with workaround

2014-12-12 Thread James Hogan
Hi Sifan,

On 11/12/14 20:06, Sifan Naeem wrote:
 Biphase decoding in the current img-ir has got a quirk, where multiple
 Interrupts are generated when an incomplete IR code is received by the
 decoder.
 
 Patch adds a work around for the quirk and enables biphase decoding.
 
 Changes from v1:
  * rebased due to conflict with img-ir/hw: Fix potential deadlock stopping 
 timer
  * spinlock taken in img_ir_suspend_timer
  * check for hw-stopping before handling quirks in img_ir_isr_hw
  * new memeber added to img_ir_priv_hw to save irq status over suspend

For future reference, the list of changes between patchset versions is
usually put after a --- so that it doesn't get included in the final
git commit message. You can also add any Acked-by/Reviewed-by tags
you've been given to new versions of patchset, assuming nothing
significant has changed in that patch (maintainers generally add
relevant tags for you, that are sent in response to the patches being
applied).

Anyway, the whole patchset looks okay to me, aside from the one question
I just asked on patch 3 of v1, which I'm not so sure about. I'll let you
decide whether that needs changing since you have the hardware to verify it.

So for the whole patchset feel free to add my:
Acked-by: James Hogan james.ho...@imgtec.com

Thanks
James

 
 Signed-off-by: Sifan Naeem sifan.na...@imgtec.com
 ---
  drivers/media/rc/img-ir/img-ir-hw.c |   60 
 +--
  drivers/media/rc/img-ir/img-ir-hw.h |4 +++
  2 files changed, 61 insertions(+), 3 deletions(-)
 
 diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
 b/drivers/media/rc/img-ir/img-ir-hw.c
 index 9cecda7..5c32f05 100644
 --- a/drivers/media/rc/img-ir/img-ir-hw.c
 +++ b/drivers/media/rc/img-ir/img-ir-hw.c
 @@ -52,6 +52,11 @@ static struct img_ir_decoder *img_ir_decoders[] = {
  
  #define IMG_IR_QUIRK_CODE_BROKEN 0x1 /* Decode is broken */
  #define IMG_IR_QUIRK_CODE_LEN_INCR   0x2 /* Bit length needs increment */
 +/*
 + * The decoder generates rapid interrupts without actually having
 + * received any new data after an incomplete IR code is decoded.
 + */
 +#define IMG_IR_QUIRK_CODE_IRQ0x4
  
  /* functions for preprocessing timings, ensuring max is set */
  
 @@ -542,6 +547,7 @@ static void img_ir_set_decoder(struct img_ir_priv *priv,
*/
   spin_unlock_irq(priv-lock);
   del_timer_sync(hw-end_timer);
 + del_timer_sync(hw-suspend_timer);
   spin_lock_irq(priv-lock);
  
   hw-stopping = false;
 @@ -861,6 +867,29 @@ static void img_ir_end_timer(unsigned long arg)
   spin_unlock_irq(priv-lock);
  }
  
 +/*
 + * Timer function to re-enable the current protocol after it had been
 + * cleared when invalid interrupts were generated due to a quirk in the
 + * img-ir decoder.
 + */
 +static void img_ir_suspend_timer(unsigned long arg)
 +{
 + struct img_ir_priv *priv = (struct img_ir_priv *)arg;
 +
 + spin_lock_irq(priv-lock);
 + /*
 +  * Don't overwrite enabled valid/match IRQs if they have already been
 +  * changed by e.g. a filter change.
 +  */
 + if ((priv-hw.quirk_suspend_irq  IMG_IR_IRQ_EDGE) ==
 + img_ir_read(priv, IMG_IR_IRQ_ENABLE))
 + img_ir_write(priv, IMG_IR_IRQ_ENABLE,
 + priv-hw.quirk_suspend_irq);
 + /* enable */
 + img_ir_write(priv, IMG_IR_CONTROL, priv-hw.reg_timings.ctrl);
 + spin_unlock_irq(priv-lock);
 +}
 +
  #ifdef CONFIG_COMMON_CLK
  static void img_ir_change_frequency(struct img_ir_priv *priv,
   struct clk_notifier_data *change)
 @@ -926,15 +955,38 @@ void img_ir_isr_hw(struct img_ir_priv *priv, u32 
 irq_status)
   if (!hw-decoder)
   return;
  
 + ct = hw-decoder-control.code_type;
 +
   ir_status = img_ir_read(priv, IMG_IR_STATUS);
 - if (!(ir_status  (IMG_IR_RXDVAL | IMG_IR_RXDVALD2)))
 + if (!(ir_status  (IMG_IR_RXDVAL | IMG_IR_RXDVALD2))) {
 + if (!(priv-hw.ct_quirks[ct]  IMG_IR_QUIRK_CODE_IRQ) ||
 + hw-stopping)
 + return;
 + /*
 +  * The below functionality is added as a work around to stop
 +  * multiple Interrupts generated when an incomplete IR code is
 +  * received by the decoder.
 +  * The decoder generates rapid interrupts without actually
 +  * having received any new data. After a single interrupt it's
 +  * expected to clear up, but instead multiple interrupts are
 +  * rapidly generated. only way to get out of this loop is to
 +  * reset the control register after a short delay.
 +  */
 + img_ir_write(priv, IMG_IR_CONTROL, 0);
 + hw-quirk_suspend_irq = img_ir_read(priv, IMG_IR_IRQ_ENABLE);
 + img_ir_write(priv, IMG_IR_IRQ_ENABLE,
 +  hw-quirk_suspend_irq  IMG_IR_IRQ_EDGE

Re: [PATCH v2 3/5] rc: img-ir: biphase enabled with workaround

2014-12-12 Thread James Hogan
On 12/12/14 12:07, James Hogan wrote:
 Hi Sifan,
 
 On 11/12/14 20:06, Sifan Naeem wrote:
 Biphase decoding in the current img-ir has got a quirk, where multiple
 Interrupts are generated when an incomplete IR code is received by the
 decoder.

 Patch adds a work around for the quirk and enables biphase decoding.

 Changes from v1:
  * rebased due to conflict with img-ir/hw: Fix potential deadlock stopping 
 timer
  * spinlock taken in img_ir_suspend_timer
  * check for hw-stopping before handling quirks in img_ir_isr_hw
  * new memeber added to img_ir_priv_hw to save irq status over suspend
 
 For future reference, the list of changes between patchset versions is
 usually put after a --- so that it doesn't get included in the final
 git commit message. You can also add any Acked-by/Reviewed-by tags
 you've been given to new versions of patchset, assuming nothing
 significant has changed in that patch (maintainers generally add
 relevant tags for you, that are sent in response to the patches being
 applied).
 
 Anyway, the whole patchset looks okay to me, aside from the one question
 I just asked on patch 3 of v1, which I'm not so sure about. I'll let you
 decide whether that needs changing since you have the hardware to verify it.
 
 So for the whole patchset feel free to add my:
 Acked-by: James Hogan james.ho...@imgtec.com

Mauro: Assuming no other changes are requested in this patchset, do you
want these resent with the moving of changelogs out of the main commit
messages?

Cheers
James



signature.asc
Description: OpenPGP digital signature


Re: [REVIEW PATCH 1/2] img-ir/hw: Avoid clearing filter for no-op protocol change

2014-12-08 Thread James Hogan
Hi Mauro,

On 04/12/14 17:38, Mauro Carvalho Chehab wrote:
 Em Mon, 1 Dec 2014 12:55:09 +
 James Hogan james.ho...@imgtec.com escreveu:
 
 When the img-ir driver is asked to change protocol, if the chosen
 decoder is already loaded then don't call img_ir_set_decoder(), so as
 not to clear the current filter.

 This is important because store_protocol() does not refresh the scancode
 filter with the new protocol if the set of enabled protocols hasn't
 actually changed, but it will still call the change_protocol() callback,
 resulting in the filter being disabled in the hardware.

 The problem can be reproduced by setting a filter, and then setting the
 protocol to the same protocol that is already set:
 $ echo nec  protocols
 $ echo 0x  filter_mask
 $ echo nec  protocols

 After this, messages which don't match the filter still get received.
 
 This should be fixed at the RC core, as this is not driver-specific.

Yes, you're right. I've fixed there and attempted backporting, and the
problem appears to have actually been introduced in commit da6e162d6a46
([media] rc-core: simplify sysfs code) which went into v3.17.

I'll send a v2.

Thanks
James

 
 Regards,
 Mauro



signature.asc
Description: OpenPGP digital signature


[REVIEW PATCH v2] rc-main: Re-apply filter for no-op protocol change

2014-12-08 Thread James Hogan
Since commit da6e162d6a46 ([media] rc-core: simplify sysfs code), when
the IR protocol is set using the sysfs interface to the same set of
protocols that are already set, store_protocols() does not refresh the
scancode filter with the new protocol, even if it has already called the
change_protocol() callback successfully. This results in the filter
being disabled in the hardware and not re-enabled until the filter is
set again using sysfs.

Fix in store_protocols() by still re-applying the filter whenever the
change_protocol() driver callback succeeded.

The problem can be reproduced with the img-ir driver by setting a
filter, and then setting the protocol to the same protocol that is
already set:
$ echo nec  protocols
$ echo 0x  filter_mask
$ echo nec  protocols

After this, messages which don't match the filter were still being
received.

Fixes: da6e162d6a46 ([media] rc-core: simplify sysfs code)
Reported-by: Sifan Naeem sifan.na...@imgtec.com
Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: David Härdeman da...@hardeman.nu
Cc: sta...@vger.kernel.org # v3.17+
Cc: linux-media@vger.kernel.org
---
Changes in v2:
- Move fix to store_protocols(). Still set filter again even if protocol
  mask hasn't been changed as a result of the protocol change (Mauro).
---
 drivers/media/rc/rc-main.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 8d3b74c5a717..fc369b033484 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -1021,16 +1021,16 @@ static ssize_t store_protocols(struct device *device,
goto out;
}
 
-   if (new_protocols == old_protocols) {
-   rc = len;
-   goto out;
+   if (new_protocols != old_protocols) {
+   *current_protocols = new_protocols;
+   IR_dprintk(1, Protocols changed to 0x%llx\n,
+  (long long)new_protocols);
}
 
-   *current_protocols = new_protocols;
-   IR_dprintk(1, Protocols changed to 0x%llx\n, (long 
long)new_protocols);
-
/*
-* If the protocol is changed the filter needs updating.
+* If a protocol change was attempted the filter may need updating, even
+* if the actual protocol mask hasn't changed (since the driver may have
+* cleared the filter).
 * Try setting the same filter with the new protocol (if any).
 * Fall back to clearing the filter.
 */
-- 
2.0.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/5] rc: img-ir: add scancode requests to a struct

2014-12-08 Thread James Hogan
On 04/12/14 15:38, Sifan Naeem wrote:
 The information being requested of hardware decode callbacks through
 the img-ir-hw scancode API is mounting up, so combine it into a struct
 which can be passed in with a single pointer rather than multiple
 pointer arguments. This allows it to be extended more easily without
 touching all the hardware decode callbacks.
 
 Signed-off-by: Sifan Naeem sifan.na...@imgtec.com

Acked-by: James Hogan james.ho...@imgtec.com

Cheers
James

 ---
  drivers/media/rc/img-ir/img-ir-hw.c|   16 +---
  drivers/media/rc/img-ir/img-ir-hw.h|   16 ++--
  drivers/media/rc/img-ir/img-ir-jvc.c   |8 
  drivers/media/rc/img-ir/img-ir-nec.c   |   24 
  drivers/media/rc/img-ir/img-ir-sanyo.c |8 
  drivers/media/rc/img-ir/img-ir-sharp.c |8 
  drivers/media/rc/img-ir/img-ir-sony.c  |   12 ++--
  7 files changed, 53 insertions(+), 39 deletions(-)
 
 diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
 b/drivers/media/rc/img-ir/img-ir-hw.c
 index ec49f94..61850a6 100644
 --- a/drivers/media/rc/img-ir/img-ir-hw.c
 +++ b/drivers/media/rc/img-ir/img-ir-hw.c
 @@ -789,20 +789,22 @@ static void img_ir_handle_data(struct img_ir_priv 
 *priv, u32 len, u64 raw)
   struct img_ir_priv_hw *hw = priv-hw;
   const struct img_ir_decoder *dec = hw-decoder;
   int ret = IMG_IR_SCANCODE;
 - u32 scancode;
 - enum rc_type protocol = RC_TYPE_UNKNOWN;
 + struct img_ir_scancode_req request;
 +
 + request.protocol = RC_TYPE_UNKNOWN;
  
   if (dec-scancode)
 - ret = dec-scancode(len, raw, protocol, scancode, 
 hw-enabled_protocols);
 + ret = dec-scancode(len, raw, hw-enabled_protocols, request);
   else if (len = 32)
 - scancode = (u32)raw;
 + request.scancode = (u32)raw;
   else if (len  32)
 - scancode = (u32)raw  ((1  len)-1);
 + request.scancode = (u32)raw  ((1  len)-1);
   dev_dbg(priv-dev, data (%u bits) = %#llx\n,
   len, (unsigned long long)raw);
   if (ret == IMG_IR_SCANCODE) {
 - dev_dbg(priv-dev, decoded scan code %#x\n, scancode);
 - rc_keydown(hw-rdev, protocol, scancode, 0);
 + dev_dbg(priv-dev, decoded scan code %#x\n,
 + request.scancode);
 + rc_keydown(hw-rdev, request.protocol, request.scancode, 0);
   img_ir_end_repeat(priv);
   } else if (ret == IMG_IR_REPEATCODE) {
   if (hw-mode == IMG_IR_M_REPEATING) {
 diff --git a/drivers/media/rc/img-ir/img-ir-hw.h 
 b/drivers/media/rc/img-ir/img-ir-hw.h
 index 8fcc16c..1fc9583 100644
 --- a/drivers/media/rc/img-ir/img-ir-hw.h
 +++ b/drivers/media/rc/img-ir/img-ir-hw.h
 @@ -133,6 +133,18 @@ struct img_ir_timing_regvals {
  #define IMG_IR_REPEATCODE1   /* repeat the previous code */
  
  /**
 + * struct img_ir_scancode_req - Scancode request data.
 + * @protocol:Protocol code of received message (defaults to
 + *   RC_TYPE_UNKNOWN).
 + * @scancode:Scan code of received message (must be written by
 + *   handler if IMG_IR_SCANCODE is returned).
 + */
 +struct img_ir_scancode_req {
 + enum rc_type protocol;
 + u32 scancode;
 +};
 +
 +/**
   * struct img_ir_decoder - Decoder settings for an IR protocol.
   * @type:Protocol types bitmap.
   * @tolerance:   Timing tolerance as a percentage (default 10%).
 @@ -162,8 +174,8 @@ struct img_ir_decoder {
   struct img_ir_control   control;
  
   /* scancode logic */
 - int (*scancode)(int len, u64 raw, enum rc_type *protocol,
 - u32 *scancode, u64 enabled_protocols);
 + int (*scancode)(int len, u64 raw, u64 enabled_protocols,
 + struct img_ir_scancode_req *request);
   int (*filter)(const struct rc_scancode_filter *in,
 struct img_ir_filter *out, u64 protocols);
  };
 diff --git a/drivers/media/rc/img-ir/img-ir-jvc.c 
 b/drivers/media/rc/img-ir/img-ir-jvc.c
 index a60dda8..d3e2fc0 100644
 --- a/drivers/media/rc/img-ir/img-ir-jvc.c
 +++ b/drivers/media/rc/img-ir/img-ir-jvc.c
 @@ -12,8 +12,8 @@
  #include img-ir-hw.h
  
  /* Convert JVC data to a scancode */
 -static int img_ir_jvc_scancode(int len, u64 raw, enum rc_type *protocol,
 -u32 *scancode, u64 enabled_protocols)
 +static int img_ir_jvc_scancode(int len, u64 raw, u64 enabled_protocols,
 +struct img_ir_scancode_req *request)
  {
   unsigned int cust, data;
  
 @@ -23,8 +23,8 @@ static int img_ir_jvc_scancode(int len, u64 raw, enum 
 rc_type *protocol,
   cust = (raw  0)  0xff;
   data = (raw  8)  0xff;
  
 - *protocol = RC_TYPE_JVC;
 - *scancode = cust  8 | data;
 + request-protocol = RC_TYPE_JVC;
 + request-scancode = cust  8 | data;
   return IMG_IR_SCANCODE;
  }
  
 diff --git a/drivers/media/rc/img-ir/img-ir-nec.c 
 b

Re: [PATCH 2/5] rc: img-ir: pass toggle bit to the rc driver

2014-12-08 Thread James Hogan
On 04/12/14 15:38, Sifan Naeem wrote:
 Add toggle bit to struct img_ir_scancode_req so that protocols can
 provide it to img_ir_handle_data(), and pass that toggle bit up to
 rc_keydown instead of 0.
 
 This is nedded for the upcoming rc-5 and rc-6 patches.

Typo (nedded).

Otherwise:
Acked-by: James Hogan james.ho...@imgtec.com

Cheers
James

 
 Signed-off-by: Sifan Naeem sifan.na...@imgtec.com
 ---
  drivers/media/rc/img-ir/img-ir-hw.c |8 +---
  drivers/media/rc/img-ir/img-ir-hw.h |2 ++
  2 files changed, 7 insertions(+), 3 deletions(-)
 
 diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
 b/drivers/media/rc/img-ir/img-ir-hw.c
 index 61850a6..4a1407b 100644
 --- a/drivers/media/rc/img-ir/img-ir-hw.c
 +++ b/drivers/media/rc/img-ir/img-ir-hw.c
 @@ -792,6 +792,7 @@ static void img_ir_handle_data(struct img_ir_priv *priv, 
 u32 len, u64 raw)
   struct img_ir_scancode_req request;
  
   request.protocol = RC_TYPE_UNKNOWN;
 + request.toggle   = 0;
  
   if (dec-scancode)
   ret = dec-scancode(len, raw, hw-enabled_protocols, request);
 @@ -802,9 +803,10 @@ static void img_ir_handle_data(struct img_ir_priv *priv, 
 u32 len, u64 raw)
   dev_dbg(priv-dev, data (%u bits) = %#llx\n,
   len, (unsigned long long)raw);
   if (ret == IMG_IR_SCANCODE) {
 - dev_dbg(priv-dev, decoded scan code %#x\n,
 - request.scancode);
 - rc_keydown(hw-rdev, request.protocol, request.scancode, 0);
 + dev_dbg(priv-dev, decoded scan code %#x, toggle %u\n,
 + request.scancode, request.toggle);
 + rc_keydown(hw-rdev, request.protocol, request.scancode,
 +request.toggle);
   img_ir_end_repeat(priv);
   } else if (ret == IMG_IR_REPEATCODE) {
   if (hw-mode == IMG_IR_M_REPEATING) {
 diff --git a/drivers/media/rc/img-ir/img-ir-hw.h 
 b/drivers/media/rc/img-ir/img-ir-hw.h
 index 1fc9583..5e59e8e 100644
 --- a/drivers/media/rc/img-ir/img-ir-hw.h
 +++ b/drivers/media/rc/img-ir/img-ir-hw.h
 @@ -138,10 +138,12 @@ struct img_ir_timing_regvals {
   *   RC_TYPE_UNKNOWN).
   * @scancode:Scan code of received message (must be written by
   *   handler if IMG_IR_SCANCODE is returned).
 + * @toggle:  Toggle bit (defaults to 0).
   */
  struct img_ir_scancode_req {
   enum rc_type protocol;
   u32 scancode;
 + u8 toggle;
  };
  
  /**
 



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 3/5] rc: img-ir: biphase enabled with workaround

2014-12-08 Thread James Hogan
On 04/12/14 15:38, Sifan Naeem wrote:
 Biphase decoding in the current img-ir has got a quirk, where multiple
 Interrupts are generated when an incomplete IR code is received by the
 decoder.
 
 Patch adds a work around for the quirk and enables biphase decoding.
 
 Signed-off-by: Sifan Naeem sifan.na...@imgtec.com
 ---
  drivers/media/rc/img-ir/img-ir-hw.c |   56 
 +--
  drivers/media/rc/img-ir/img-ir-hw.h |2 ++
  2 files changed, 55 insertions(+), 3 deletions(-)
 
 diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
 b/drivers/media/rc/img-ir/img-ir-hw.c
 index 4a1407b..a977467 100644
 --- a/drivers/media/rc/img-ir/img-ir-hw.c
 +++ b/drivers/media/rc/img-ir/img-ir-hw.c
 @@ -52,6 +52,11 @@ static struct img_ir_decoder *img_ir_decoders[] = {
  
  #define IMG_IR_QUIRK_CODE_BROKEN 0x1 /* Decode is broken */
  #define IMG_IR_QUIRK_CODE_LEN_INCR   0x2 /* Bit length needs increment */
 +/*
 + * The decoder generates rapid interrupts without actually having
 + * received any new data after an incomplete IR code is decoded.
 + */
 +#define IMG_IR_QUIRK_CODE_IRQ0x4
  
  /* functions for preprocessing timings, ensuring max is set */
  
 @@ -547,6 +552,7 @@ static void img_ir_set_decoder(struct img_ir_priv *priv,
  
   /* stop the end timer and switch back to normal mode */
   del_timer_sync(hw-end_timer);
 + del_timer_sync(hw-suspend_timer);

FYI, this'll need rebasing due to conflicting with img-ir/hw: Fix
potential deadlock stopping timer. The new del_timer_sync will need to
be when spin lock isn't held, i.e. still next to the other one, and
don't forget to ensure that suspend_timer doesn't get started if
hw-stopping.

   hw-mode = IMG_IR_M_NORMAL;
  
   /* clear the wakeup scancode filter */
 @@ -843,6 +849,26 @@ static void img_ir_end_timer(unsigned long arg)
   spin_unlock_irq(priv-lock);
  }
  
 +/*
 + * Timer function to re-enable the current protocol after it had been
 + * cleared when invalid interrupts were generated due to a quirk in the
 + * img-ir decoder.
 + */
 +static void img_ir_suspend_timer(unsigned long arg)
 +{
 + struct img_ir_priv *priv = (struct img_ir_priv *)arg;
 +

You should take the spin lock for most of this function now that
img-ir/hw: Fix potential deadlock stopping timer is applied and it is
safe to do so.

 + img_ir_write(priv, IMG_IR_IRQ_CLEAR,
 + IMG_IR_IRQ_ALL  ~IMG_IR_IRQ_EDGE);
 +
 + /* Don't set IRQ if it has changed in a different context. */

Wouldn't hurt to clarify this while you're at it (it confused me for a
moment thinking it was concerned about the enabled raw event IRQs
(IMG_IR_IRQ_EDGE) changing).

Maybe Don't overwrite enabled valid/match IRQs if they have already
been changed by e.g. a filter change.

Should you even be clearing IRQs in that case? Maybe safer to just treat
that case as a return immediately without touching anything sort of
situation.

 + if ((priv-hw.suspend_irqen  IMG_IR_IRQ_EDGE) ==
 + img_ir_read(priv, IMG_IR_IRQ_ENABLE))
 + img_ir_write(priv, IMG_IR_IRQ_ENABLE, priv-hw.suspend_irqen);
 + /* enable */
 + img_ir_write(priv, IMG_IR_CONTROL, priv-hw.reg_timings.ctrl);
 +}
 +
  #ifdef CONFIG_COMMON_CLK
  static void img_ir_change_frequency(struct img_ir_priv *priv,
   struct clk_notifier_data *change)
 @@ -908,15 +934,37 @@ void img_ir_isr_hw(struct img_ir_priv *priv, u32 
 irq_status)
   if (!hw-decoder)
   return;
  
 + ct = hw-decoder-control.code_type;
 +
   ir_status = img_ir_read(priv, IMG_IR_STATUS);
 - if (!(ir_status  (IMG_IR_RXDVAL | IMG_IR_RXDVALD2)))
 + if (!(ir_status  (IMG_IR_RXDVAL | IMG_IR_RXDVALD2))) {
 + if (!(priv-hw.ct_quirks[ct]  IMG_IR_QUIRK_CODE_IRQ))

(I suggest adding || hw-stopping to this case)

 + return;
 + /*
 +  * The below functionality is added as a work around to stop
 +  * multiple Interrupts generated when an incomplete IR code is
 +  * received by the decoder.
 +  * The decoder generates rapid interrupts without actually
 +  * having received any new data. After a single interrupt it's
 +  * expected to clear up, but instead multiple interrupts are
 +  * rapidly generated. only way to get out of this loop is to
 +  * reset the control register after a short delay.
 +  */
 + img_ir_write(priv, IMG_IR_CONTROL, 0);
 + hw-suspend_irqen = img_ir_read(priv, IMG_IR_IRQ_ENABLE);

You're reusing hw-suspend_irqen. What if you get this workaround being
activated between img_ir_enable_wake() and img_ir_disable_wake()? I
suggest just using a new img_ir_priv_hw member.

The rest looks reasonable to me, even if unfortunate that it is
necessary in the first place.

Thanks for the hard work!

Cheers
James

 + 

Re: [PATCH 4/5] rc: img-ir: add philips rc5 decoder module

2014-12-08 Thread James Hogan
On 04/12/14 15:38, Sifan Naeem wrote:
 Add img-ir module for decoding Philips rc5 protocol.
 
 Signed-off-by: Sifan Naeem sifan.na...@imgtec.com
 ---
  drivers/media/rc/img-ir/Kconfig  |7 +++
  drivers/media/rc/img-ir/Makefile |1 +
  drivers/media/rc/img-ir/img-ir-hw.c  |3 ++
  drivers/media/rc/img-ir/img-ir-hw.h  |1 +
  drivers/media/rc/img-ir/img-ir-rc5.c |   88 
 ++
  5 files changed, 100 insertions(+)
  create mode 100644 drivers/media/rc/img-ir/img-ir-rc5.c
 
 diff --git a/drivers/media/rc/img-ir/Kconfig b/drivers/media/rc/img-ir/Kconfig
 index 03ba9fc..b5b114f 100644
 --- a/drivers/media/rc/img-ir/Kconfig
 +++ b/drivers/media/rc/img-ir/Kconfig
 @@ -59,3 +59,10 @@ config IR_IMG_SANYO
   help
  Say Y here to enable support for the Sanyo protocol (used by Sanyo,
  Aiwa, Chinon remotes) in the ImgTec infrared decoder block.
 +
 +config IR_IMG_RC5
 + bool Phillips RC5 protocol support

I think that should be Philips (if wikipedia is anything to go by).

Same elsewhere in this patch and patch 5.

Other than that,
Acked-by: James Hogan james.ho...@imgtec.com

(Note, I don't have RC-5/RC-6 capable hardware yet so can't test this
support)

Thanks
James

 + depends on IR_IMG_HW
 + help
 +Say Y here to enable support for the RC5 protocol in the ImgTec
 +infrared decoder block.
 diff --git a/drivers/media/rc/img-ir/Makefile 
 b/drivers/media/rc/img-ir/Makefile
 index 92a459d..898b1b8 100644
 --- a/drivers/media/rc/img-ir/Makefile
 +++ b/drivers/media/rc/img-ir/Makefile
 @@ -6,6 +6,7 @@ img-ir-$(CONFIG_IR_IMG_JVC)   += img-ir-jvc.o
  img-ir-$(CONFIG_IR_IMG_SONY) += img-ir-sony.o
  img-ir-$(CONFIG_IR_IMG_SHARP)+= img-ir-sharp.o
  img-ir-$(CONFIG_IR_IMG_SANYO)+= img-ir-sanyo.o
 +img-ir-$(CONFIG_IR_IMG_RC5)  += img-ir-rc5.o
  img-ir-objs  := $(img-ir-y)
  
  obj-$(CONFIG_IR_IMG) += img-ir.o
 diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
 b/drivers/media/rc/img-ir/img-ir-hw.c
 index a977467..322cdf8 100644
 --- a/drivers/media/rc/img-ir/img-ir-hw.c
 +++ b/drivers/media/rc/img-ir/img-ir-hw.c
 @@ -42,6 +42,9 @@ static struct img_ir_decoder *img_ir_decoders[] = {
  #ifdef CONFIG_IR_IMG_SANYO
   img_ir_sanyo,
  #endif
 +#ifdef CONFIG_IR_IMG_RC5
 + img_ir_rc5,
 +#endif
   NULL
  };
  
 diff --git a/drivers/media/rc/img-ir/img-ir-hw.h 
 b/drivers/media/rc/img-ir/img-ir-hw.h
 index 8578aa7..f124ec5 100644
 --- a/drivers/media/rc/img-ir/img-ir-hw.h
 +++ b/drivers/media/rc/img-ir/img-ir-hw.h
 @@ -187,6 +187,7 @@ extern struct img_ir_decoder img_ir_jvc;
  extern struct img_ir_decoder img_ir_sony;
  extern struct img_ir_decoder img_ir_sharp;
  extern struct img_ir_decoder img_ir_sanyo;
 +extern struct img_ir_decoder img_ir_rc5;
  
  /**
   * struct img_ir_reg_timings - Reg values for decoder timings at clock rate.
 diff --git a/drivers/media/rc/img-ir/img-ir-rc5.c 
 b/drivers/media/rc/img-ir/img-ir-rc5.c
 new file mode 100644
 index 000..e1a0829
 --- /dev/null
 +++ b/drivers/media/rc/img-ir/img-ir-rc5.c
 @@ -0,0 +1,88 @@
 +/*
 + * ImgTec IR Decoder setup for Phillips RC-5 protocol.
 + *
 + * Copyright 2012-2014 Imagination Technologies Ltd.
 + *
 + * 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.
 + */
 +
 +#include img-ir-hw.h
 +
 +/* Convert RC5 data to a scancode */
 +static int img_ir_rc5_scancode(int len, u64 raw, u64 enabled_protocols,
 + struct img_ir_scancode_req *request)
 +{
 + unsigned int addr, cmd, tgl, start;
 +
 + /* Quirk in the decoder shifts everything by 2 to the left. */
 + raw   = 2;
 +
 + start   =  (raw  13)   0x01;
 + tgl =  (raw  11)   0x01;
 + addr=  (raw   6)   0x1f;
 + cmd =   raw  0x3f;
 + /*
 +  * 12th bit is used to extend the command in extended RC5 and has
 +  * no effect on standard RC5.
 +  */
 + cmd += ((raw  12)  0x01) ? 0 : 0x40;
 +
 + if (!start)
 + return -EINVAL;
 +
 + request-protocol = RC_TYPE_RC5;
 + request-scancode = addr  8 | cmd;
 + request-toggle   = tgl;
 + return IMG_IR_SCANCODE;
 +}
 +
 +/* Convert RC5 scancode to RC5 data filter */
 +static int img_ir_rc5_filter(const struct rc_scancode_filter *in,
 +  struct img_ir_filter *out, u64 protocols)
 +{
 + /* Not supported by the hw. */
 + return -EINVAL;
 +}
 +
 +/*
 + * RC-5 decoder
 + * see http://www.sbprojects.com/knowledge/ir/rc5.php
 + */
 +struct img_ir_decoder img_ir_rc5 = {
 + .type  = RC_BIT_RC5,
 + .control   = {
 + .bitoriend2 = 1,
 + .code_type  = IMG_IR_CODETYPE_BIPHASE,
 + .decodend2  = 1,
 + },
 + /* main timings

Re: [PATCH 5/5] rc: img-ir: add philips rc6 decoder module

2014-12-08 Thread James Hogan
On 04/12/14 15:38, Sifan Naeem wrote:
 Add img-ir module for decoding Philips rc6 protocol.
 
 Signed-off-by: Sifan Naeem sifan.na...@imgtec.com

Aside from the Philips thing:

Acked-by: James Hogan james.ho...@imgtec.com

(It's unpleasant having unexplained timings for RC-6, but it's better
than no RC-6 support, and hopefully in the future it can be improved).

Cheers
James

 ---
  drivers/media/rc/img-ir/Kconfig  |8 +++
  drivers/media/rc/img-ir/Makefile |1 +
  drivers/media/rc/img-ir/img-ir-hw.c  |3 +
  drivers/media/rc/img-ir/img-ir-hw.h  |1 +
  drivers/media/rc/img-ir/img-ir-rc6.c |  117 
 ++
  5 files changed, 130 insertions(+)
  create mode 100644 drivers/media/rc/img-ir/img-ir-rc6.c
 
 diff --git a/drivers/media/rc/img-ir/Kconfig b/drivers/media/rc/img-ir/Kconfig
 index b5b114f..4d3fca9 100644
 --- a/drivers/media/rc/img-ir/Kconfig
 +++ b/drivers/media/rc/img-ir/Kconfig
 @@ -66,3 +66,11 @@ config IR_IMG_RC5
   help
  Say Y here to enable support for the RC5 protocol in the ImgTec
  infrared decoder block.
 +
 +config IR_IMG_RC6
 + bool Phillips RC6 protocol support
 + depends on IR_IMG_HW
 + help
 +Say Y here to enable support for the RC6 protocol in the ImgTec
 +infrared decoder block.
 +Note: This version only supports mode 0.
 diff --git a/drivers/media/rc/img-ir/Makefile 
 b/drivers/media/rc/img-ir/Makefile
 index 898b1b8..8e6d458 100644
 --- a/drivers/media/rc/img-ir/Makefile
 +++ b/drivers/media/rc/img-ir/Makefile
 @@ -7,6 +7,7 @@ img-ir-$(CONFIG_IR_IMG_SONY)  += img-ir-sony.o
  img-ir-$(CONFIG_IR_IMG_SHARP)+= img-ir-sharp.o
  img-ir-$(CONFIG_IR_IMG_SANYO)+= img-ir-sanyo.o
  img-ir-$(CONFIG_IR_IMG_RC5)  += img-ir-rc5.o
 +img-ir-$(CONFIG_IR_IMG_RC6)  += img-ir-rc6.o
  img-ir-objs  := $(img-ir-y)
  
  obj-$(CONFIG_IR_IMG) += img-ir.o
 diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
 b/drivers/media/rc/img-ir/img-ir-hw.c
 index 322cdf8..3b70dc2 100644
 --- a/drivers/media/rc/img-ir/img-ir-hw.c
 +++ b/drivers/media/rc/img-ir/img-ir-hw.c
 @@ -45,6 +45,9 @@ static struct img_ir_decoder *img_ir_decoders[] = {
  #ifdef CONFIG_IR_IMG_RC5
   img_ir_rc5,
  #endif
 +#ifdef CONFIG_IR_IMG_RC6
 + img_ir_rc6,
 +#endif
   NULL
  };
  
 diff --git a/drivers/media/rc/img-ir/img-ir-hw.h 
 b/drivers/media/rc/img-ir/img-ir-hw.h
 index f124ec5..c7b6e1a 100644
 --- a/drivers/media/rc/img-ir/img-ir-hw.h
 +++ b/drivers/media/rc/img-ir/img-ir-hw.h
 @@ -188,6 +188,7 @@ extern struct img_ir_decoder img_ir_sony;
  extern struct img_ir_decoder img_ir_sharp;
  extern struct img_ir_decoder img_ir_sanyo;
  extern struct img_ir_decoder img_ir_rc5;
 +extern struct img_ir_decoder img_ir_rc6;
  
  /**
   * struct img_ir_reg_timings - Reg values for decoder timings at clock rate.
 diff --git a/drivers/media/rc/img-ir/img-ir-rc6.c 
 b/drivers/media/rc/img-ir/img-ir-rc6.c
 new file mode 100644
 index 000..bcd0822
 --- /dev/null
 +++ b/drivers/media/rc/img-ir/img-ir-rc6.c
 @@ -0,0 +1,117 @@
 +/*
 + * ImgTec IR Decoder setup for Phillips RC-6 protocol.
 + *
 + * Copyright 2012-2014 Imagination Technologies Ltd.
 + *
 + * 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.
 + */
 +
 +#include img-ir-hw.h
 +
 +/* Convert RC6 data to a scancode */
 +static int img_ir_rc6_scancode(int len, u64 raw, u64 enabled_protocols,
 + struct img_ir_scancode_req *request)
 +{
 + unsigned int addr, cmd, mode, trl1, trl2;
 +
 + /*
 +  * Due to a side effect of the decoder handling the double length
 +  * Trailer bit, the header information is a bit scrambled, and the
 +  * raw data is shifted incorrectly.
 +  * This workaround effectively recovers the header bits.
 +  *
 +  * The Header field should look like this:
 +  *
 +  * StartBit ModeBit2 ModeBit1 ModeBit0 TrailerBit
 +  *
 +  * But what we get is:
 +  *
 +  * ModeBit2 ModeBit1 ModeBit0 TrailerBit1 TrailerBit2
 +  *
 +  * The start bit is not important to recover the scancode.
 +  */
 +
 + raw = 27;
 +
 + trl1= (raw   17)   0x01;
 + trl2= (raw   16)   0x01;
 +
 + mode= (raw   18)   0x07;
 + addr= (raw8)   0xff;
 + cmd =  raw   0xff;
 +
 + /*
 +  * Due to the above explained irregularity the trailer bits cannot
 +  * have the same value.
 +  */
 + if (trl1 == trl2)
 + return -EINVAL;
 +
 + /* Only mode 0 supported for now */
 + if (mode)
 + return -EINVAL;
 +
 + request-protocol = RC_TYPE_RC6_0;
 + request-scancode = addr  8 | cmd;
 + request-toggle   = trl2;
 + return IMG_IR_SCANCODE;
 +}
 +
 +/* Convert RC6

[REVIEW PATCH 0/2] img-ir: Some more fixes

2014-12-01 Thread James Hogan
A few more fixes for the img-ir RC driver in addition to the ones I
posted a couple of weeks ago.

The first patch fixes some broken behaviour when the same protocol is
set twice and the effective scancode filter gets cleared as a result.

The second patch fixes a potential deadlock and lockdep splat due to the
repeat end timer being del_timer_sync'd with the spin lock held when
changing protocols.

The second patch here depends on img-ir/hw: Always read data to clear
buffer (patch 1 in the previous img-ir patchset) to avoid conflicts, so
that patch should be applied first.

I've tagged both for stable (v3.15+).

Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Sifan Naeem sifan.na...@imgtec.com
Cc: linux-media@vger.kernel.org

James Hogan (2):
  img-ir/hw: Avoid clearing filter for no-op protocol change
  img-ir/hw: Fix potential deadlock stopping timer

 drivers/media/rc/img-ir/img-ir-hw.c | 28 +---
 drivers/media/rc/img-ir/img-ir-hw.h |  3 +++
 2 files changed, 28 insertions(+), 3 deletions(-)

-- 
2.0.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEW PATCH 1/2] img-ir/hw: Avoid clearing filter for no-op protocol change

2014-12-01 Thread James Hogan
When the img-ir driver is asked to change protocol, if the chosen
decoder is already loaded then don't call img_ir_set_decoder(), so as
not to clear the current filter.

This is important because store_protocol() does not refresh the scancode
filter with the new protocol if the set of enabled protocols hasn't
actually changed, but it will still call the change_protocol() callback,
resulting in the filter being disabled in the hardware.

The problem can be reproduced by setting a filter, and then setting the
protocol to the same protocol that is already set:
$ echo nec  protocols
$ echo 0x  filter_mask
$ echo nec  protocols

After this, messages which don't match the filter still get received.

Reported-by: Sifan Naeem sifan.na...@imgtec.com
Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: sta...@vger.kernel.org # v3.15+
Cc: linux-media@vger.kernel.org
---
 drivers/media/rc/img-ir/img-ir-hw.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
b/drivers/media/rc/img-ir/img-ir-hw.c
index 9db065344b41..1566337c1059 100644
--- a/drivers/media/rc/img-ir/img-ir-hw.c
+++ b/drivers/media/rc/img-ir/img-ir-hw.c
@@ -643,6 +643,12 @@ static int img_ir_change_protocol(struct rc_dev *dev, u64 
*ir_type)
continue;
if (*ir_type  dec-type) {
*ir_type = dec-type;
+   /*
+* We don't want to clear the filter if nothing is
+* changing as it won't get set again.
+*/
+   if (dec == hw-decoder)
+   return 0;
img_ir_set_decoder(priv, dec, *ir_type);
goto success;
}
-- 
2.0.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEW PATCH 2/2] img-ir/hw: Fix potential deadlock stopping timer

2014-12-01 Thread James Hogan
The end timer is used for switching back from repeat code timings when
no repeat codes have been received for a certain amount of time. When
the protocol is changed, the end timer is deleted synchronously with
del_timer_sync(), however this takes place while holding the main spin
lock, and the timer handler also needs to acquire the spin lock.

This opens the possibility of a deadlock on an SMP system if the
protocol is changed just as the repeat timer is expiring. One CPU could
end up in img_ir_set_decoder() holding the lock and waiting for the end
timer to complete, while the other CPU is stuck in the timer handler
spinning on the lock held by the first CPU.

Lockdep also spots a possible lock inversion in the same code, since
img_ir_set_decoder() acquires the img-ir lock before the timer lock, but
the timer handler will try and acquire them the other way around:

=
[ INFO: possible irq lock inversion dependency detected ]
3.18.0-rc5+ #957 Not tainted
-
swapper/0/0 just changed the state of lock:
 (((hw-end_timer))){+.-...}, at: [4006ae5c] _call_timer_fn+0x0/0xfc
but this lock was taken by another, HARDIRQ-safe lock in the past:
 ((priv-lock)-rlock#2){-.}

and interrupts could create inverse lock ordering between them.

other info that might help us debug this:
 Possible interrupt unsafe locking scenario:

   CPU0CPU1
   
  lock(((hw-end_timer)));
   local_irq_disable();
   lock((priv-lock)-rlock#2);
   lock(((hw-end_timer)));
  Interrupt
lock((priv-lock)-rlock#2);

 *** DEADLOCK ***

This is fixed by releasing the main spin lock while performing the
del_timer_sync() call. The timer is prevented from restarting before the
lock is reacquired by a new stopping flag which img_ir_handle_data()
checks before updating the timer.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Sifan Naeem sifan.na...@imgtec.com
Cc: sta...@vger.kernel.org # v3.15+
Cc: linux-media@vger.kernel.org
---
This patch depends on img-ir/hw: Always read data to clear buffer from
my recent img-ir patchset to avoid a conflict.
---
 drivers/media/rc/img-ir/img-ir-hw.c | 22 +++---
 drivers/media/rc/img-ir/img-ir-hw.h |  3 +++
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
b/drivers/media/rc/img-ir/img-ir-hw.c
index 1566337c1059..76eaa323ae51 100644
--- a/drivers/media/rc/img-ir/img-ir-hw.c
+++ b/drivers/media/rc/img-ir/img-ir-hw.c
@@ -530,6 +530,22 @@ static void img_ir_set_decoder(struct img_ir_priv *priv,
u32 ir_status, irq_en;
spin_lock_irq(priv-lock);
 
+   /*
+* First record that the protocol is being stopped so that the end timer
+* isn't restarted while we're trying to stop it.
+*/
+   hw-stopping = true;
+
+   /*
+* Release the lock to stop the end timer, since the end timer handler
+* acquires the lock and we don't want to deadlock waiting for it.
+*/
+   spin_unlock_irq(priv-lock);
+   del_timer_sync(hw-end_timer);
+   spin_lock_irq(priv-lock);
+
+   hw-stopping = false;
+
/* switch off and disable interrupts */
img_ir_write(priv, IMG_IR_CONTROL, 0);
irq_en = img_ir_read(priv, IMG_IR_IRQ_ENABLE);
@@ -547,8 +563,7 @@ static void img_ir_set_decoder(struct img_ir_priv *priv,
img_ir_read(priv, IMG_IR_DATA_LW);
img_ir_read(priv, IMG_IR_DATA_UP);
 
-   /* stop the end timer and switch back to normal mode */
-   del_timer_sync(hw-end_timer);
+   /* switch back to normal mode */
hw-mode = IMG_IR_M_NORMAL;
 
/* clear the wakeup scancode filter */
@@ -825,7 +840,8 @@ static void img_ir_handle_data(struct img_ir_priv *priv, 
u32 len, u64 raw)
}
 
 
-   if (dec-repeat) {
+   /* we mustn't update the end timer while trying to stop it */
+   if (dec-repeat  !hw-stopping) {
unsigned long interval;
 
img_ir_begin_repeat(priv);
diff --git a/drivers/media/rc/img-ir/img-ir-hw.h 
b/drivers/media/rc/img-ir/img-ir-hw.h
index a8c6a8d40206..5c2b216c5fe3 100644
--- a/drivers/media/rc/img-ir/img-ir-hw.h
+++ b/drivers/media/rc/img-ir/img-ir-hw.h
@@ -211,6 +211,8 @@ enum img_ir_mode {
  * @flags: IMG_IR_F_*.
  * @filters:   HW filters (derived from scancode filters).
  * @mode:  Current decode mode.
+ * @stopping:  Indicates that decoder is being taken down and timers
+ * should not be restarted.
  * @suspend_irqen: Saved IRQ enable mask over suspend.
  */
 struct img_ir_priv_hw {
@@ -226,6 +228,7 @@ struct img_ir_priv_hw {
struct img_ir_filterfilters[RC_FILTER_MAX];
 
enum

Re: [REVIEW] Submitting Media Patches

2014-11-17 Thread James Hogan
On 22 October 2014 15:12, Hans Verkuil hverk...@xs4all.nl wrote:
 How to submit patches for a stable kernel
 =

 The standard method is to add this tag:

 Cc: sta...@vger.kernel.org

 possibly with a comment saying to which versions it should be applied, like:

 Cc: sta...@vger.kernel.org  # for v3.5 and up

Maybe put angled brackets around the email address. Some versions of
git-send-email get confused by the comment otherwise and try sending
to e.g. sta...@vger.kernel.org #3.11.

Cheers
James
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEW PATCH 0/5] img-ir: Some fixes

2014-11-17 Thread James Hogan
Here are a few fixes for the img-ir RC driver.

Patch 1 is the important one. I've tagged it for stable.

The other 4 are minor fixes/improvements that don't need backporting to
stable.

Dylan Rajaratnam (1):
  img-ir/hw: Always read data to clear buffer

James Hogan (4):
  img-ir/hw: Drop [un]register_decoder declarations
  img-ir: Depend on METAG or MIPS or COMPILE_TEST
  img-ir: Don't set driver's module owner
  MAINTAINERS: Add myself as img-ir maintainer

 MAINTAINERS   | 5 +
 drivers/media/rc/img-ir/Kconfig   | 1 +
 drivers/media/rc/img-ir/img-ir-core.c | 1 -
 drivers/media/rc/img-ir/img-ir-hw.c   | 6 --
 drivers/media/rc/img-ir/img-ir-hw.h   | 3 ---
 5 files changed, 10 insertions(+), 6 deletions(-)

-- 
2.0.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEW PATCH 4/5] img-ir: Don't set driver's module owner

2014-11-17 Thread James Hogan
Don't bother setting .owner = THIS_MODULE, since it's already handled by
the platform_driver_register macro.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: linux-media@vger.kernel.org
---
 drivers/media/rc/img-ir/img-ir-core.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/media/rc/img-ir/img-ir-core.c 
b/drivers/media/rc/img-ir/img-ir-core.c
index a0cac2f09109..77c78de4f5bf 100644
--- a/drivers/media/rc/img-ir/img-ir-core.c
+++ b/drivers/media/rc/img-ir/img-ir-core.c
@@ -166,7 +166,6 @@ MODULE_DEVICE_TABLE(of, img_ir_match);
 static struct platform_driver img_ir_driver = {
.driver = {
.name = img-ir,
-   .owner  = THIS_MODULE,
.of_match_table = img_ir_match,
.pm = img_ir_pmops,
},
-- 
2.0.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEW PATCH 3/5] img-ir: Depend on METAG or MIPS or COMPILE_TEST

2014-11-17 Thread James Hogan
The ImgTec Infrared decoder block which img-ir drives is only used in
IMGWorks SoCs so far, such as the TZ1090 (Meta based) and the upcoming
Pistachio (MIPS based). Therefore make the driver depend on METAG (for
TZ1090) or MIPS (for Pistachio) or COMPILE_TEST (so that it is included
in x86 allmodconfig builds), to avoid cluttering the Kconfig menu with
drivers for hardware that isn't yet available on other platforms.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: linux-media@vger.kernel.org
---
 drivers/media/rc/img-ir/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/media/rc/img-ir/Kconfig b/drivers/media/rc/img-ir/Kconfig
index 03ba9fc170fb..580715c7fc5e 100644
--- a/drivers/media/rc/img-ir/Kconfig
+++ b/drivers/media/rc/img-ir/Kconfig
@@ -1,6 +1,7 @@
 config IR_IMG
tristate ImgTec IR Decoder
depends on RC_CORE
+   depends on METAG || MIPS || COMPILE_TEST
select IR_IMG_HW if !IR_IMG_RAW
help
   Say Y or M here if you want to use the ImgTec infrared decoder
-- 
2.0.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEW PATCH 2/5] img-ir/hw: Drop [un]register_decoder declarations

2014-11-17 Thread James Hogan
The img_ir_register_decoder() and img_ir_unregister_decoder() functions
were dropped prior to the img-ir driver being applied to simplify the
protocol decoder setup. However the declarations of these functions in
img-ir-hw.h were still included. Delete them since they're completely
unused.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: linux-media@vger.kernel.org
---
 drivers/media/rc/img-ir/img-ir-hw.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/media/rc/img-ir/img-ir-hw.h 
b/drivers/media/rc/img-ir/img-ir-hw.h
index 8fcc16c32c5b..a8c6a8d40206 100644
--- a/drivers/media/rc/img-ir/img-ir-hw.h
+++ b/drivers/media/rc/img-ir/img-ir-hw.h
@@ -186,9 +186,6 @@ struct img_ir_reg_timings {
struct img_ir_timing_regvalsrtimings;
 };
 
-int img_ir_register_decoder(struct img_ir_decoder *dec);
-void img_ir_unregister_decoder(struct img_ir_decoder *dec);
-
 struct img_ir_priv;
 
 #ifdef CONFIG_IR_IMG_HW
-- 
2.0.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEW PATCH 5/5] MAINTAINERS: Add myself as img-ir maintainer

2014-11-17 Thread James Hogan
Add myself as the maintainer for the Imagination Technologies Infrared
Decoder driver.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: linux-media@vger.kernel.org
---
 MAINTAINERS | 5 +
 1 file changed, 5 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index ea4d0058fd1b..814cf15448ad 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -4757,6 +4757,11 @@ L:   linux-security-mod...@vger.kernel.org
 S: Supported
 F: security/integrity/ima/
 
+IMGTEC IR DECODER DRIVER
+M: James Hogan james.ho...@imgtec.com
+S: Maintained
+F: drivers/media/rc/img-ir/
+
 IMS TWINTURBO FRAMEBUFFER DRIVER
 L: linux-fb...@vger.kernel.org
 S: Orphan
-- 
2.0.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[REVIEW PATCH FOR v3.18 1/5] img-ir/hw: Always read data to clear buffer

2014-11-17 Thread James Hogan
From: Dylan Rajaratnam dylan.rajarat...@imgtec.com

A problem was found on Polaris where if the unit it booted via the power
button on the infrared remote then the next button press on the remote
would return the key code used to power on the unit.

The sequence is:
 - The polaris powered off but with the powerdown controller (PDC) block
   still powered.
 - Press power key on remote, IR block receives the key.
 - Kernel starts, IR code is in IMG_IR_DATA_x but neither IMG_IR_RXDVAL
   or IMG_IR_RXDVALD2 are set.
 - Wait any amount of time.
 - Press any key.
 - IMG_IR_RXDVAL or IMG_IR_RXDVALD2 is set but IMG_IR_DATA_x is
   unchanged since the powerup key data was never read.

This is worked around by always reading the IMG_IR_DATA_x in
img_ir_set_decoder(), rather than only when the IMG_IR_RXDVAL or
IMG_IR_RXDVALD2 bit is set.

Signed-off-by: Dylan Rajaratnam dylan.rajarat...@imgtec.com
Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: linux-media@vger.kernel.org
Cc: sta...@vger.kernel.org # v3.15+
---
 drivers/media/rc/img-ir/img-ir-hw.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
b/drivers/media/rc/img-ir/img-ir-hw.c
index ec49f94425fc..9db065344b41 100644
--- a/drivers/media/rc/img-ir/img-ir-hw.c
+++ b/drivers/media/rc/img-ir/img-ir-hw.c
@@ -541,10 +541,12 @@ static void img_ir_set_decoder(struct img_ir_priv *priv,
if (ir_status  (IMG_IR_RXDVAL | IMG_IR_RXDVALD2)) {
ir_status = ~(IMG_IR_RXDVAL | IMG_IR_RXDVALD2);
img_ir_write(priv, IMG_IR_STATUS, ir_status);
-   img_ir_read(priv, IMG_IR_DATA_LW);
-   img_ir_read(priv, IMG_IR_DATA_UP);
}
 
+   /* always read data to clear buffer if IR wakes the device */
+   img_ir_read(priv, IMG_IR_DATA_LW);
+   img_ir_read(priv, IMG_IR_DATA_UP);
+
/* stop the end timer and switch back to normal mode */
del_timer_sync(hw-end_timer);
hw-mode = IMG_IR_M_NORMAL;
-- 
2.0.4

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 01/29] img-ir: fix sparse warnings

2014-08-20 Thread James Hogan
On Thursday 21 August 2014 00:59:00 Hans Verkuil wrote:
 From: Hans Verkuil hans.verk...@cisco.com
 
 drivers/media/rc/img-ir/img-ir-nec.c:111:23: warning: symbol 'img_ir_nec'
 was not declared. Should it be static?
 drivers/media/rc/img-ir/img-ir-jvc.c:54:23: warning: symbol 'img_ir_jvc'
 was not declared. Should it be static?
 drivers/media/rc/img-ir/img-ir-sony.c:120:23: warning: symbol 'img_ir_sony'
 was not declared. Should it be static?
 drivers/media/rc/img-ir/img-ir-sharp.c:75:23: warning: symbol
 'img_ir_sharp' was not declared. Should it be static?
 drivers/media/rc/img-ir/img-ir-sanyo.c:82:23: warning: symbol
 'img_ir_sanyo' was not declared. Should it be static?
 
 Signed-off-by: Hans Verkuil hans.verk...@cisco.com

Acked-by: James Hogan james.ho...@imgtec.com

Thanks
James
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 0/9] rc: Add IR encode based wakeup filtering

2014-07-25 Thread James Hogan
Hi Mauro,

On Wednesday 23 July 2014 16:39:36 Mauro Carvalho Chehab wrote:
 Em Fri, 14 Mar 2014 23:04:10 +
 
 James Hogan ja...@albanarts.com escreveu:
  A recent discussion about proposed interfaces for setting up the
  hardware wakeup filter lead to the conclusion that it could help to have
  the generic capability to encode and modulate scancodes into raw IR
  events so that drivers for hardware with a low level wake filter (on the
  level of pulse/space durations) can still easily implement the higher
  level scancode interface that is proposed.
  
  I posted an RFC patchset showing how this could work, and Antti Seppälä
  posted additional patches to support rc5-sz and nuvoton-cir. This
  patchset improves the original RFC patches and combines  updates
  Antti's patches.
  
  I'm happy these patches are a good start at tackling the problem, as
  long as Antti is happy with them and they work for him of course.
  
  Future work could include:
   - Encoders for more protocols.
   - Carrier signal events (no use unless a driver makes use of it).
  
  Patch 1 adds the new encode API.
  Patches 2-3 adds some modulation helpers.
  Patches 4-6 adds some raw encode implementations.
  Patch 7 adds some rc-core support for encode based wakeup filtering.
  Patch 8 adds debug loopback of encoded scancode when filter set.
  Patch 9 (untested) adds encode based wakeup filtering to nuvoton-cir.
 
  Changes in v2:
 Any news about this patch series? There are some comments about them,
 so I'll be tagging it as changes requested at patchwork, waiting
 for a v3 (or is it already there in the middle of the 49 patches from
 David?).

This patch series seems to have been forgotten. I do have a few changes on top 
of v2 to address the review comments, so as you say I should probably rebase 
and do a v3 at some point.

Cheers
James
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6 2/3] ARM: sunxi: Add driver for sunxi IR controller

2014-05-13 Thread James Hogan
Hi Alexander,

Just a few probe error handling suggestions...

On 13/05/14 19:39, Alexander Bersenev wrote:
 +static int sunxi_ir_probe(struct platform_device *pdev)
 +{
 + int ret = 0;
 + unsigned long tmp = 0;
 +
 + struct device *dev = pdev-dev;
 + struct device_node *dn = dev-of_node;
 + struct resource *res;
 + struct sunxi_ir *ir;
 +
 + ir = devm_kzalloc(dev, sizeof(struct sunxi_ir), GFP_KERNEL);
 + if (!ir)
 + return -ENOMEM;
 +
 + /* Clock */
 + ir-apb_clk = devm_clk_get(dev, apb);
 + if (IS_ERR(ir-apb_clk)) {
 + dev_err(dev, failed to get a apb clock.\n);
 + return -EINVAL;

Does it make sense to return PTR_ERR(ir-apb_clk) here?

 + }
 + ir-clk = devm_clk_get(dev, ir);
 + if (IS_ERR(ir-clk)) {
 + dev_err(dev, failed to get a ir clock.\n);
 + return -EINVAL;

and here

 + }
 +
 + ret = clk_set_rate(ir-clk, SUNXI_IR_BASE_CLK);
 + if (ret) {
 + dev_err(dev, set ir base clock failed!\n);
 + return -EINVAL;

return ret?

 + }
 +
 + if (clk_prepare_enable(ir-apb_clk)) {
 + dev_err(dev, try to enable apb_ir_clk failed\n);
 + return -EINVAL;
 + }
 +
 + if (clk_prepare_enable(ir-clk)) {
 + dev_err(dev, try to enable ir_clk failed\n);
 + ret = -EINVAL;
 + goto exit_clkdisable_apb_clk;
 + }
 +
 + /* IO */
 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 +
 + ir-base = devm_ioremap_resource(dev, res);
 + if (IS_ERR(ir-base)) {
 + dev_err(dev, failed to map registers\n);
 + ret = -ENOMEM;

PTR_ERR again?

 + goto exit_clkdisable_clk;
 + }
 +
 + /* IRQ */
 + ir-irq = platform_get_irq(pdev, 0);
 + if (ir-irq  0) {
 + dev_err(dev, no irq resource\n);
 + ret = -EINVAL;

ret = ir-irq?

 + goto exit_clkdisable_clk;
 + }
 +
 + ret = devm_request_irq(dev, ir-irq, sunxi_ir_irq, 0, SUNXI_IR_DEV, ir);
 + if (ret) {
 + dev_err(dev, failed request irq\n);
 + ret = -EINVAL;

necessary?

 + goto exit_clkdisable_clk;
 + }
 +
 + ir-rc = rc_allocate_device();
 +
 + if (!ir-rc) {
 + dev_err(dev, failed to allocate device\n);
 + ret = -ENOMEM;
 + goto exit_clkdisable_clk;
 + }
 +
 + ir-rc-priv = ir;
 + ir-rc-input_name = SUNXI_IR_DEV;
 + ir-rc-input_phys = sunxi-ir/input0;
 + ir-rc-input_id.bustype = BUS_HOST;
 + ir-rc-input_id.vendor = 0x0001;
 + ir-rc-input_id.product = 0x0001;
 + ir-rc-input_id.version = 0x0100;
 + ir-map_name = of_get_property(dn, linux,rc-map-name, NULL);
 + ir-rc-map_name = ir-map_name ?: RC_MAP_EMPTY;
 + ir-rc-dev.parent = dev;
 + ir-rc-driver_type = RC_DRIVER_IR_RAW;
 + rc_set_allowed_protocols(ir-rc, RC_BIT_ALL);
 + ir-rc-rx_resolution = SUNXI_IR_SAMPLE;
 + ir-rc-timeout = MS_TO_NS(SUNXI_IR_TIMEOUT);
 + ir-rc-driver_name = SUNXI_IR_DEV;
 +
 + ret = rc_register_device(ir-rc);
 + if (ret) {
 + dev_err(dev, failed to register rc device\n);
 + ret = -EINVAL;

same again

 + goto exit_free_dev;
 + }
 +

Cheers
James
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 41/49] rc-core: rename mutex

2014-04-10 Thread James Hogan
On Friday 04 April 2014 01:34:43 David Härdeman wrote:
 Having a mutex named lock is a bit misleading.

Why? A mutex is a type of lock so what's the problem?

A little grep'ing and sed'ing reveals that out of the 1578 unique mutex names 
in the kernel source I have to hand, 540 contain lock, and 921 contain 
mutex.

Cheers
James

 
 Signed-off-by: David Härdeman da...@hardeman.nu
 ---
  drivers/media/rc/img-ir/img-ir-hw.c |4 ++-
  drivers/media/rc/rc-main.c  |   42
 ++- include/media/rc-core.h |  
  5 ++--
  3 files changed, 25 insertions(+), 26 deletions(-)
 
 diff --git a/drivers/media/rc/img-ir/img-ir-hw.c
 b/drivers/media/rc/img-ir/img-ir-hw.c index 5bc7903..a9abbb4 100644
 --- a/drivers/media/rc/img-ir/img-ir-hw.c
 +++ b/drivers/media/rc/img-ir/img-ir-hw.c
 @@ -666,11 +666,11 @@ static void img_ir_set_protocol(struct img_ir_priv
 *priv, u64 proto) {
   struct rc_dev *rdev = priv-hw.rdev;
 
 - mutex_lock(rdev-lock);
 + mutex_lock(rdev-mutex);
   rdev-enabled_protocols = proto;
   rdev-allowed_wakeup_protocols = proto;
   rdev-enabled_wakeup_protocols = proto;
 - mutex_unlock(rdev-lock);
 + mutex_unlock(rdev-mutex);
  }
 
  /* Set up IR decoders */
 diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
 index 7caca4f..bd4dfab 100644
 --- a/drivers/media/rc/rc-main.c
 +++ b/drivers/media/rc/rc-main.c
 @@ -109,7 +109,7 @@ int rc_open(struct rc_dev *dev)
  {
   int err = 0;
 
 - mutex_lock(dev-lock);
 + mutex_lock(dev-mutex);
 
   if (dev-dead)
   err = -ENODEV;
 @@ -119,7 +119,7 @@ int rc_open(struct rc_dev *dev)
   dev-users--;
   }
 
 - mutex_unlock(dev-lock);
 + mutex_unlock(dev-mutex);
 
   return err;
  }
 @@ -127,12 +127,12 @@ EXPORT_SYMBOL_GPL(rc_open);
 
  void rc_close(struct rc_dev *dev)
  {
 - mutex_lock(dev-lock);
 + mutex_lock(dev-mutex);
 
   if (!dev-dead  !--dev-users  dev-close)
   dev-close(dev);
 
 - mutex_unlock(dev-lock);
 + mutex_unlock(dev-mutex);
  }
  EXPORT_SYMBOL_GPL(rc_close);
 
 @@ -322,7 +322,7 @@ struct rc_filter_attribute {
   * It returns the protocol names of supported protocols.
   * Enabled protocols are printed in brackets.
   *
 - * dev-lock is taken to guard against races between store_protocols and
 + * dev-mutex is taken to guard against races between store_protocols and
   * show_protocols.
   */
  static ssize_t show_protocols(struct device *device,
 @@ -339,7 +339,7 @@ static ssize_t show_protocols(struct device *device,
   return -EINVAL;
 
   rc_event(dev, RC_KEY, RC_KEY_REPEAT, 1);
 - mutex_lock(dev-lock);
 + mutex_lock(dev-mutex);
 
   if (fattr-type == RC_FILTER_NORMAL) {
   enabled = dev-enabled_protocols;
 @@ -349,7 +349,7 @@ static ssize_t show_protocols(struct device *device,
   allowed = dev-allowed_wakeup_protocols;
   }
 
 - mutex_unlock(dev-lock);
 + mutex_unlock(dev-mutex);
 
   IR_dprintk(1, %s: allowed - 0x%llx, enabled - 0x%llx\n,
  __func__, (long long)allowed, (long long)enabled);
 @@ -449,7 +449,7 @@ static int parse_protocol_change(u64 *protocols, const
 char *buf) * See parse_protocol_change() for the valid commands.
   * Returns @len on success or a negative error code.
   *
 - * dev-lock is taken to guard against races between store_protocols and
 + * dev-mutex is taken to guard against races between store_protocols and
   * show_protocols.
   */
  static ssize_t store_protocols(struct device *device,
 @@ -488,7 +488,7 @@ static ssize_t store_protocols(struct device *device,
   return -EINVAL;
   }
 
 - mutex_lock(dev-lock);
 + mutex_lock(dev-mutex);
 
   old_protocols = *current_protocols;
   new_protocols = old_protocols;
 @@ -532,7 +532,7 @@ static ssize_t store_protocols(struct device *device,
   rc = len;
 
  out:
 - mutex_unlock(dev-lock);
 + mutex_unlock(dev-mutex);
   return rc;
  }
 
 @@ -550,7 +550,7 @@ out:
   * Bits of the filter value corresponding to set bits in the filter mask
 are * compared against input scancodes and non-matching scancodes are
 discarded. *
 - * dev-lock is taken to guard against races between store_filter and
 + * dev-mutex is taken to guard against races between store_filter and
   * show_filter.
   */
  static ssize_t show_filter(struct device *device,
 @@ -571,12 +571,12 @@ static ssize_t show_filter(struct device *device,
   else
   filter = dev-scancode_wakeup_filter;
 
 - mutex_lock(dev-lock);
 + mutex_lock(dev-mutex);
   if (fattr-mask)
   val = filter-mask;
   else
   val = filter-data;
 - mutex_unlock(dev-lock);
 + mutex_unlock(dev-mutex);
 
   return sprintf(buf, %#x\n, val);
  }
 @@ -597,7 +597,7 @@ static ssize_t show_filter(struct device *device,
   * Bits of the filter value corresponding to set 

Re: [PATCH 05/49] rc-core: split dev-s_filter

2014-04-04 Thread James Hogan
Hi David,

On 4 April 2014 00:31, David Härdeman da...@hardeman.nu wrote:
 Overloading dev-s_filter to do two different functions (set wakeup filters
 and generic hardware filters) makes it impossible to tell what the
 hardware actually supports, so create a separate dev-s_wakeup_filter and
 make the distinction explicit.

 Signed-off-by: David Härdeman da...@hardeman.nu
 ---
  drivers/media/rc/img-ir/img-ir-hw.c |   15 ++-

I think we crossed emails. My comments on your earlier submission of
this patch about the removal of generic scancode filter code that has
crept in to the patch apply here too (sorry I didn't spot that when I
first looked at it!).

But if you fix that you're welcome to my:
Acked-by: James Hogan james.ho...@imgtec.com

Cheers
James

  drivers/media/rc/rc-main.c  |   31 +++
  include/media/rc-core.h |6 --
  3 files changed, 37 insertions(+), 15 deletions(-)

 diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
 b/drivers/media/rc/img-ir/img-ir-hw.c
 index aec79f7..871a9b3 100644
 --- a/drivers/media/rc/img-ir/img-ir-hw.c
 +++ b/drivers/media/rc/img-ir/img-ir-hw.c
 @@ -504,6 +504,18 @@ unlock:
 return ret;
  }

 +static int img_ir_set_normal_filter(struct rc_dev *dev,
 +   struct rc_scancode_filter *sc_filter)
 +{
 +   return img_ir_set_filter(dev, RC_FILTER_NORMAL, sc_filter);
 +}
 +
 +static int img_ir_set_wakeup_filter(struct rc_dev *dev,
 +   struct rc_scancode_filter *sc_filter)
 +{
 +   return img_ir_set_filter(dev, RC_FILTER_WAKEUP, sc_filter);
 +}
 +
  /**
   * img_ir_set_decoder() - Set the current decoder.
   * @priv:  IR private data.
 @@ -988,7 +1000,8 @@ int img_ir_probe_hw(struct img_ir_priv *priv)
 rdev-map_name = RC_MAP_EMPTY;
 rc_set_allowed_protocols(rdev, img_ir_allowed_protos(priv));
 rdev-input_name = IMG Infrared Decoder;
 -   rdev-s_filter = img_ir_set_filter;
 +   rdev-s_filter = img_ir_set_normal_filter;
 +   rdev-s_wakeup_filter = img_ir_set_wakeup_filter;

 /* Register hardware decoder */
 error = rc_register_device(rdev);
 diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
 index c0bfd50..ba955ac 100644
 --- a/drivers/media/rc/rc-main.c
 +++ b/drivers/media/rc/rc-main.c
 @@ -929,6 +929,7 @@ static ssize_t store_protocols(struct device *device,
 int rc, i, count = 0;
 ssize_t ret;
 int (*change_protocol)(struct rc_dev *dev, u64 *rc_type);
 +   int (*set_filter)(struct rc_dev *dev, struct rc_scancode_filter 
 *filter);
 struct rc_scancode_filter local_filter, *filter;

 /* Device is being removed */
 @@ -1013,24 +1014,27 @@ static ssize_t store_protocols(struct device *device,
  * Fall back to clearing the filter.
  */
 filter = dev-scancode_filters[fattr-type];
 +   set_filter = (fattr-type == RC_FILTER_NORMAL)
 +   ? dev-s_filter : dev-s_wakeup_filter;
 +
 if (old_type != type  filter-mask) {
 local_filter = *filter;
 if (!type) {
 /* no protocol = clear filter */
 ret = -1;
 -   } else if (!dev-s_filter) {
 +   } else if (!set_filter) {
 /* generic filtering = accept any filter */
 ret = 0;
 } else {
 /* hardware filtering = try setting, otherwise clear 
 */
 -   ret = dev-s_filter(dev, fattr-type, local_filter);
 +   ret = set_filter(dev, local_filter);
 }
 if (ret  0) {
 /* clear the filter */
 local_filter.data = 0;
 local_filter.mask = 0;
 -   if (dev-s_filter)
 -   dev-s_filter(dev, fattr-type, 
 local_filter);
 +   if (set_filter)
 +   set_filter(dev, local_filter);
 }

 /* commit the new filter */
 @@ -1112,6 +1116,7 @@ static ssize_t store_filter(struct device *device,
 struct rc_scancode_filter local_filter, *filter;
 int ret;
 unsigned long val;
 +   int (*set_filter)(struct rc_dev *dev, struct rc_scancode_filter 
 *filter);

 /* Device is being removed */
 if (!dev)
 @@ -1121,9 +1126,11 @@ static ssize_t store_filter(struct device *device,
 if (ret  0)
 return ret;

 -   /* Scancode filter not supported (but still accept 0) */
 -   if (!dev-s_filter  fattr-type != RC_FILTER_NORMAL)
 -   return val ? -EINVAL : count;
 +   /* Can the scancode filter be set? */
 +   set_filter = (fattr-type == RC_FILTER_NORMAL)
 +   ? dev-s_filter : dev-s_wakeup_filter;
 +   if (!set_filter

Re: [PATCH 04/49] rc-core: do not change 32bit NEC scancode format for now

2014-04-04 Thread James Hogan
Hi David,

On 4 April 2014 00:31, David Härdeman da...@hardeman.nu wrote:
 diff --git a/drivers/media/rc/img-ir/img-ir-nec.c 
 b/drivers/media/rc/img-ir/img-ir-nec.c
 index c0111d6..ee45795 100644
 --- a/drivers/media/rc/img-ir/img-ir-nec.c
 +++ b/drivers/media/rc/img-ir/img-ir-nec.c

  /* Convert NEC data to a scancode */
  static int img_ir_nec_scancode(int len, u64 raw, enum rc_type *protocol,
 @@ -23,11 +24,11 @@ static int img_ir_nec_scancode(int len, u64 raw, enum 
 rc_type *protocol,
 data_inv = (raw  24)  0xff;
 if ((data_inv ^ data) != 0xff) {
 /* 32-bit NEC (used by Apple and TiVo remotes) */
 -   /* scan encoding: aaAAddDD */
 -   *scancode = addr_inv  24 |
 -   addr  16 |
 -   data_inv   8 |
 -   data;
 +   /* scan encoding: AAaaDDdd (LSBit first) */

This scan encoding of NEC32 interprets the  raw data MSBit first (i.e.
the MSBit of scancode is the first bit received), so this comment is
wrong.

 +   *scancode = bitrev8(addr)  24 |
 +   bitrev8(addr_inv)  16 |
 +   bitrev8(data)   8 |
 +   bitrev8(data_inv);
 } else if ((addr_inv ^ addr) != 0xff) {
 /* Extended NEC */
 /* scan encoding: AAaaDD */
 @@ -56,13 +57,15 @@ static int img_ir_nec_filter(const struct 
 rc_scancode_filter *in,

 if ((in-data | in-mask)  0xff00) {
 /* 32-bit NEC (used by Apple and TiVo remotes) */
 -   /* scan encoding: aaAAddDD */
 -   addr_inv   = (in-data  24)  0xff;
 -   addr_inv_m = (in-mask  24)  0xff;
 -   addr   = (in-data  16)  0xff;
 -   addr_m = (in-mask  16)  0xff;
 -   data_inv   = (in-data   8)  0xff;
 -   data_inv_m = (in-mask   8)  0xff;
 +   /* scan encoding: AAaaDDdd (LSBit first) */

same here

The actual code looks fine now though. If you fix those two comments:
Acked-by: James Hogan james.ho...@imgtec.com

Cheers
James

 +   addr   = bitrev8(in-data  24);
 +   addr_m = bitrev8(in-mask  24);
 +   addr_inv   = bitrev8(in-data  16);
 +   addr_inv_m = bitrev8(in-mask  16);
 +   data   = bitrev8(in-data   8);
 +   data_m = bitrev8(in-mask   8);
 +   data_inv   = bitrev8(in-data   0);
 +   data_inv_m = bitrev8(in-mask   0);
 } else if ((in-data | in-mask)  0x00ff) {
 /* Extended NEC */
 /* scan encoding AAaaDD */
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 06/49] rc-core: remove generic scancode filter

2014-04-04 Thread James Hogan
Hi David,

On 4 April 2014 00:31, David Härdeman da...@hardeman.nu wrote:
 The generic scancode filtering has questionable value and makes it
 impossible to determine from userspace if there is an actual
 scancode hw filter present or not.

 So revert the generic parts.

I've already mentioned in a different email that reverting the last
two hunks of b8c7d915087c97a21fa415fa0e860e59739da202 should be in
this patch rather than combined into patch 5.

But if you fix that you're welcome to my:
Reviewed-by: James Hogan james.ho...@imgtec.com

Thanks
James


 Based on a patch from James Hogan james.ho...@imgtec.com, but this
 version also makes sure that only the valid sysfs files are created
 in the first place.

 v2: correct dev-s_filter check

 Signed-off-by: David Härdeman da...@hardeman.nu
 ---
  drivers/media/rc/rc-main.c |   67 
 +---
  include/media/rc-core.h|2 +
  2 files changed, 46 insertions(+), 23 deletions(-)

 diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
 index ba955ac..26c266b 100644
 --- a/drivers/media/rc/rc-main.c
 +++ b/drivers/media/rc/rc-main.c
 @@ -634,7 +634,6 @@ EXPORT_SYMBOL_GPL(rc_repeat);
  static void ir_do_keydown(struct rc_dev *dev, enum rc_type protocol,
   u32 scancode, u32 keycode, u8 toggle)
  {
 -   struct rc_scancode_filter *filter;
 bool new_event = (!dev-keypressed   ||
   dev-last_protocol != protocol ||
   dev-last_scancode != scancode ||
 @@ -643,11 +642,6 @@ static void ir_do_keydown(struct rc_dev *dev, enum 
 rc_type protocol,
 if (new_event  dev-keypressed)
 ir_do_keyup(dev, false);

 -   /* Generic scancode filtering */
 -   filter = dev-scancode_filters[RC_FILTER_NORMAL];
 -   if (filter-mask  ((scancode ^ filter-data)  filter-mask))
 -   return;
 -
 input_event(dev-input_dev, EV_MSC, MSC_SCAN, scancode);

 if (new_event  keycode != KEY_RESERVED) {
 @@ -1017,14 +1011,11 @@ static ssize_t store_protocols(struct device *device,
 set_filter = (fattr-type == RC_FILTER_NORMAL)
 ? dev-s_filter : dev-s_wakeup_filter;

 -   if (old_type != type  filter-mask) {
 +   if (set_filter  old_type != type  filter-mask) {
 local_filter = *filter;
 if (!type) {
 /* no protocol = clear filter */
 ret = -1;
 -   } else if (!set_filter) {
 -   /* generic filtering = accept any filter */
 -   ret = 0;
 } else {
 /* hardware filtering = try setting, otherwise clear 
 */
 ret = set_filter(dev, local_filter);
 @@ -1033,8 +1024,7 @@ static ssize_t store_protocols(struct device *device,
 /* clear the filter */
 local_filter.data = 0;
 local_filter.mask = 0;
 -   if (set_filter)
 -   set_filter(dev, local_filter);
 +   set_filter(dev, local_filter);
 }

 /* commit the new filter */
 @@ -1078,7 +1068,10 @@ static ssize_t show_filter(struct device *device,
 return -EINVAL;

 mutex_lock(dev-lock);
 -   if (fattr-mask)
 +   if ((fattr-type == RC_FILTER_NORMAL  !dev-s_filter) ||
 +   (fattr-type == RC_FILTER_WAKEUP  !dev-s_wakeup_filter))
 +   val = 0;
 +   else if (fattr-mask)
 val = dev-scancode_filters[fattr-type].mask;
 else
 val = dev-scancode_filters[fattr-type].data;
 @@ -1202,27 +1195,45 @@ static RC_FILTER_ATTR(wakeup_filter, S_IRUGO|S_IWUSR,
  static RC_FILTER_ATTR(wakeup_filter_mask, S_IRUGO|S_IWUSR,
   show_filter, store_filter, RC_FILTER_WAKEUP, true);

 -static struct attribute *rc_dev_attrs[] = {
 +static struct attribute *rc_dev_protocol_attrs[] = {
 dev_attr_protocols.attr.attr,
 +   NULL,
 +};
 +
 +static struct attribute_group rc_dev_protocol_attr_grp = {
 +   .attrs  = rc_dev_protocol_attrs,
 +};
 +
 +static struct attribute *rc_dev_wakeup_protocol_attrs[] = {
 dev_attr_wakeup_protocols.attr.attr,
 +   NULL,
 +};
 +
 +static struct attribute_group rc_dev_wakeup_protocol_attr_grp = {
 +   .attrs  = rc_dev_wakeup_protocol_attrs,
 +};
 +
 +static struct attribute *rc_dev_filter_attrs[] = {
 dev_attr_filter.attr.attr,
 dev_attr_filter_mask.attr.attr,
 -   dev_attr_wakeup_filter.attr.attr,
 -   dev_attr_wakeup_filter_mask.attr.attr,
 NULL,
  };

 -static struct attribute_group rc_dev_attr_grp = {
 -   .attrs  = rc_dev_attrs,
 +static struct attribute_group rc_dev_filter_attr_grp = {
 +   .attrs  = rc_dev_filter_attrs,
 +};
 +
 +static struct attribute

Re: [PATCH 1/3] rc-core: do not change 32bit NEC scancode format for now

2014-04-04 Thread James Hogan
On Saturday 05 April 2014 00:05:56 David Härdeman wrote:
 This reverts 18bc17448147e93f31cc9b1a83be49f1224657b2
 
 The patch ignores the fact that NEC32 scancodes are generated not only in
 the NEC raw decoder but also directly in some drivers. Whichever approach
 is chosen it should be consistent across drivers and this patch needs more
 discussion.
 
 Furthermore, I'm convinced that we have to stop playing games trying to
 decipher the meaning of NEC scancodes (what's the customer/vendor/address,
 which byte is the MSB, etc).
 
 This patch is in preparation for the next few patches in this series.
 
 v2: make sure img-ir scancodes are bitrev8():ed as well
 
 v3: update comments
 
 Signed-off-by: David Härdeman da...@hardeman.nu

Acked-by: James Hogan james.ho...@imgtec.com

Thanks
James

 ---
  drivers/media/rc/img-ir/img-ir-nec.c |   27 ++-
  drivers/media/rc/ir-nec-decoder.c|5 --
  drivers/media/rc/keymaps/rc-tivo.c   |   86
 +- 3 files changed, 59 insertions(+), 59
 deletions(-)
 
 diff --git a/drivers/media/rc/img-ir/img-ir-nec.c
 b/drivers/media/rc/img-ir/img-ir-nec.c index e7a731b..751d9d9 100644
 --- a/drivers/media/rc/img-ir/img-ir-nec.c
 +++ b/drivers/media/rc/img-ir/img-ir-nec.c
 @@ -5,6 +5,7 @@
   */
 
  #include img-ir-hw.h
 +#include linux/bitrev.h
 
  /* Convert NEC data to a scancode */
  static int img_ir_nec_scancode(int len, u64 raw, int *scancode, u64
 protocols) @@ -22,11 +23,11 @@ static int img_ir_nec_scancode(int len, u64
 raw, int *scancode, u64 protocols) data_inv = (raw  24)  0xff;
   if ((data_inv ^ data) != 0xff) {
   /* 32-bit NEC (used by Apple and TiVo remotes) */
 - /* scan encoding: aaAAddDD */
 - *scancode = addr_inv  24 |
 - addr  16 |
 - data_inv   8 |
 - data;
 + /* scan encoding: as transmitted, MSBit = first received bit */
 + *scancode = bitrev8(addr)  24 |
 + bitrev8(addr_inv)  16 |
 + bitrev8(data)   8 |
 + bitrev8(data_inv);
   } else if ((addr_inv ^ addr) != 0xff) {
   /* Extended NEC */
   /* scan encoding: AAaaDD */
 @@ -54,13 +55,15 @@ static int img_ir_nec_filter(const struct
 rc_scancode_filter *in,
 
   if ((in-data | in-mask)  0xff00) {
   /* 32-bit NEC (used by Apple and TiVo remotes) */
 - /* scan encoding: aaAAddDD */
 - addr_inv   = (in-data  24)  0xff;
 - addr_inv_m = (in-mask  24)  0xff;
 - addr   = (in-data  16)  0xff;
 - addr_m = (in-mask  16)  0xff;
 - data_inv   = (in-data   8)  0xff;
 - data_inv_m = (in-mask   8)  0xff;
 + /* scan encoding: as transmitted, MSBit = first received bit */
 + addr   = bitrev8(in-data  24);
 + addr_m = bitrev8(in-mask  24);
 + addr_inv   = bitrev8(in-data  16);
 + addr_inv_m = bitrev8(in-mask  16);
 + data   = bitrev8(in-data   8);
 + data_m = bitrev8(in-mask   8);
 + data_inv   = bitrev8(in-data   0);
 + data_inv_m = bitrev8(in-mask   0);
   } else if ((in-data | in-mask)  0x00ff) {
   /* Extended NEC */
   /* scan encoding AAaaDD */
 diff --git a/drivers/media/rc/ir-nec-decoder.c
 b/drivers/media/rc/ir-nec-decoder.c index 9de1791..35c42e5 100644
 --- a/drivers/media/rc/ir-nec-decoder.c
 +++ b/drivers/media/rc/ir-nec-decoder.c
 @@ -172,10 +172,7 @@ static int ir_nec_decode(struct rc_dev *dev, struct
 ir_raw_event ev) if (send_32bits) {
   /* NEC transport, but modified protocol, used by at
* least Apple and TiVo remotes */
 - scancode = not_address  24 |
 -address  16 |
 -not_command   8 |
 -command;
 + scancode = data-bits;
   IR_dprintk(1, NEC (modified) scancode 0x%08x\n, 
 scancode);
   } else if ((address ^ not_address) != 0xff) {
   /* Extended NEC */
 diff --git a/drivers/media/rc/keymaps/rc-tivo.c
 b/drivers/media/rc/keymaps/rc-tivo.c index 5cc1b45..454e062 100644
 --- a/drivers/media/rc/keymaps/rc-tivo.c
 +++ b/drivers/media/rc/keymaps/rc-tivo.c
 @@ -15,62 +15,62 @@
   * Initial mapping is for the TiVo remote included in the Nero LiquidTV
 bundle, * which also ships with a TiVo-branded IR transceiver, supported by
 the mceusb * driver. Note that the remote uses an NEC-ish protocol, but
 instead of having - * a command/not_command pair, it has a vendor ID of
 0x3085, but some keys, the + * a command/not_command pair, it has a vendor
 ID of 0xa10c, but some keys, the * NEC extended checksums do pass, so the
 table

Re: [PATCH 2/3] rc-core: split dev-s_filter

2014-04-04 Thread James Hogan
On Saturday 05 April 2014 00:06:01 David Härdeman wrote:
 Overloading dev-s_filter to do two different functions (set wakeup filters
 and generic hardware filters) makes it impossible to tell what the
 hardware actually supports, so create a separate dev-s_wakeup_filter and
 make the distinction explicit.
 
 v2: hopefully address James' comments on what should be moved from this to
 the next patch.
 
 Signed-off-by: David Härdeman da...@hardeman.nu

Acked-by: James Hogan james.ho...@imgtec.com

Thanks
James

 ---
  drivers/media/rc/img-ir/img-ir-hw.c |   15 ++-
  drivers/media/rc/rc-main.c  |   24 +---
  include/media/rc-core.h |6 --
  3 files changed, 35 insertions(+), 10 deletions(-)
 
 diff --git a/drivers/media/rc/img-ir/img-ir-hw.c
 b/drivers/media/rc/img-ir/img-ir-hw.c index 579a52b..0127dd2 100644
 --- a/drivers/media/rc/img-ir/img-ir-hw.c
 +++ b/drivers/media/rc/img-ir/img-ir-hw.c
 @@ -504,6 +504,18 @@ unlock:
   return ret;
  }
 
 +static int img_ir_set_normal_filter(struct rc_dev *dev,
 + struct rc_scancode_filter *sc_filter)
 +{
 + return img_ir_set_filter(dev, RC_FILTER_NORMAL, sc_filter);
 +}
 +
 +static int img_ir_set_wakeup_filter(struct rc_dev *dev,
 + struct rc_scancode_filter *sc_filter)
 +{
 + return img_ir_set_filter(dev, RC_FILTER_WAKEUP, sc_filter);
 +}
 +
  /**
   * img_ir_set_decoder() - Set the current decoder.
   * @priv:IR private data.
 @@ -986,7 +998,8 @@ int img_ir_probe_hw(struct img_ir_priv *priv)
   rdev-map_name = RC_MAP_EMPTY;
   rc_set_allowed_protocols(rdev, img_ir_allowed_protos(priv));
   rdev-input_name = IMG Infrared Decoder;
 - rdev-s_filter = img_ir_set_filter;
 + rdev-s_filter = img_ir_set_normal_filter;
 + rdev-s_wakeup_filter = img_ir_set_wakeup_filter;
 
   /* Register hardware decoder */
   error = rc_register_device(rdev);
 diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
 index 99697aa..ecbc20c 100644
 --- a/drivers/media/rc/rc-main.c
 +++ b/drivers/media/rc/rc-main.c
 @@ -923,6 +923,7 @@ static ssize_t store_protocols(struct device *device,
   int rc, i, count = 0;
   ssize_t ret;
   int (*change_protocol)(struct rc_dev *dev, u64 *rc_type);
 + int (*set_filter)(struct rc_dev *dev, struct rc_scancode_filter 
 *filter);
   struct rc_scancode_filter local_filter, *filter;
 
   /* Device is being removed */
 @@ -1007,24 +1008,27 @@ static ssize_t store_protocols(struct device
 *device, * Fall back to clearing the filter.
*/
   filter = dev-scancode_filters[fattr-type];
 + set_filter = (fattr-type == RC_FILTER_NORMAL)
 + ? dev-s_filter : dev-s_wakeup_filter;
 +
   if (old_type != type  filter-mask) {
   local_filter = *filter;
   if (!type) {
   /* no protocol = clear filter */
   ret = -1;
 - } else if (!dev-s_filter) {
 + } else if (!set_filter) {
   /* generic filtering = accept any filter */
   ret = 0;
   } else {
   /* hardware filtering = try setting, otherwise clear */
 - ret = dev-s_filter(dev, fattr-type, local_filter);
 + ret = set_filter(dev, local_filter);
   }
   if (ret  0) {
   /* clear the filter */
   local_filter.data = 0;
   local_filter.mask = 0;
 - if (dev-s_filter)
 - dev-s_filter(dev, fattr-type, local_filter);
 + if (set_filter)
 + set_filter(dev, local_filter);
   }
 
   /* commit the new filter */
 @@ -1106,6 +1110,7 @@ static ssize_t store_filter(struct device *device,
   struct rc_scancode_filter local_filter, *filter;
   int ret;
   unsigned long val;
 + int (*set_filter)(struct rc_dev *dev, struct rc_scancode_filter 
 *filter);
 
   /* Device is being removed */
   if (!dev)
 @@ -1115,8 +1120,11 @@ static ssize_t store_filter(struct device *device,
   if (ret  0)
   return ret;
 
 + set_filter = (fattr-type == RC_FILTER_NORMAL) ? dev-s_filter :
 +  dev-s_wakeup_filter;
 +
   /* Scancode filter not supported (but still accept 0) */
 - if (!dev-s_filter  fattr-type != RC_FILTER_NORMAL)
 + if (!set_filter  fattr-type == RC_FILTER_WAKEUP)
   return val ? -EINVAL : count;
 
   mutex_lock(dev-lock);
 @@ -1128,13 +1136,15 @@ static ssize_t store_filter(struct device *device,
   local_filter.mask = val;
   else
   local_filter.data = val;
 +
   if (!dev-enabled_protocols[fattr-type]  local_filter.mask) {
   /* refuse to set a filter

Re: [PATCH 3/3] rc-core: remove generic scancode filter

2014-04-04 Thread James Hogan
On Saturday 05 April 2014 00:06:06 David Härdeman wrote:
 The generic scancode filtering has questionable value and makes it
 impossible to determine from userspace if there is an actual
 scancode hw filter present or not.
 
 So revert the generic parts.
 
 Based on a patch from James Hogan james.ho...@imgtec.com, but this
 version also makes sure that only the valid sysfs files are created
 in the first place.
 
 v2: correct dev-s_filter check
 
 v3: move some parts over from the previous patch
 
 Signed-off-by: David Härdeman da...@hardeman.nu

Acked-by: James Hogan james.ho...@imgtec.com

Thanks
James

 ---
  drivers/media/rc/rc-main.c |   88
 +++- include/media/rc-core.h|  
  2 +
  2 files changed, 55 insertions(+), 35 deletions(-)
 
 diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
 index ecbc20c..970b93d 100644
 --- a/drivers/media/rc/rc-main.c
 +++ b/drivers/media/rc/rc-main.c
 @@ -633,19 +633,13 @@ EXPORT_SYMBOL_GPL(rc_repeat);
  static void ir_do_keydown(struct rc_dev *dev, int scancode,
 u32 keycode, u8 toggle)
  {
 - struct rc_scancode_filter *filter;
 - bool new_event = !dev-keypressed ||
 -  dev-last_scancode != scancode ||
 -  dev-last_toggle != toggle;
 + bool new_event = (!dev-keypressed   ||
 +   dev-last_scancode != scancode ||
 +   dev-last_toggle != toggle);
 
   if (new_event  dev-keypressed)
   ir_do_keyup(dev, false);
 
 - /* Generic scancode filtering */
 - filter = dev-scancode_filters[RC_FILTER_NORMAL];
 - if (filter-mask  ((scancode ^ filter-data)  filter-mask))
 - return;
 -
   input_event(dev-input_dev, EV_MSC, MSC_SCAN, scancode);
 
   if (new_event  keycode != KEY_RESERVED) {
 @@ -1011,14 +1005,11 @@ static ssize_t store_protocols(struct device
 *device, set_filter = (fattr-type == RC_FILTER_NORMAL)
   ? dev-s_filter : dev-s_wakeup_filter;
 
 - if (old_type != type  filter-mask) {
 + if (set_filter  old_type != type  filter-mask) {
   local_filter = *filter;
   if (!type) {
   /* no protocol = clear filter */
   ret = -1;
 - } else if (!set_filter) {
 - /* generic filtering = accept any filter */
 - ret = 0;
   } else {
   /* hardware filtering = try setting, otherwise clear */
   ret = set_filter(dev, local_filter);
 @@ -1027,8 +1018,7 @@ static ssize_t store_protocols(struct device *device,
   /* clear the filter */
   local_filter.data = 0;
   local_filter.mask = 0;
 - if (set_filter)
 - set_filter(dev, local_filter);
 + set_filter(dev, local_filter);
   }
 
   /* commit the new filter */
 @@ -1072,7 +1062,10 @@ static ssize_t show_filter(struct device *device,
   return -EINVAL;
 
   mutex_lock(dev-lock);
 - if (fattr-mask)
 + if ((fattr-type == RC_FILTER_NORMAL  !dev-s_filter) ||
 + (fattr-type == RC_FILTER_WAKEUP  !dev-s_wakeup_filter))
 + val = 0;
 + else if (fattr-mask)
   val = dev-scancode_filters[fattr-type].mask;
   else
   val = dev-scancode_filters[fattr-type].data;
 @@ -1120,12 +1113,11 @@ static ssize_t store_filter(struct device *device,
   if (ret  0)
   return ret;
 
 + /* Can the scancode filter be set? */
   set_filter = (fattr-type == RC_FILTER_NORMAL) ? dev-s_filter :
dev-s_wakeup_filter;
 -
 - /* Scancode filter not supported (but still accept 0) */
 - if (!set_filter  fattr-type == RC_FILTER_WAKEUP)
 - return val ? -EINVAL : count;
 + if (!set_filter)
 + return -EINVAL;
 
   mutex_lock(dev-lock);
 
 @@ -1143,11 +1135,9 @@ static ssize_t store_filter(struct device *device,
   goto unlock;
   }
 
 - if (set_filter) {
 - ret = set_filter(dev, local_filter);
 - if (ret  0)
 - goto unlock;
 - }
 + ret = set_filter(dev, local_filter);
 + if (ret  0)
 + goto unlock;
 
   /* Success, commit the new filter */
   *filter = local_filter;
 @@ -1199,27 +1189,45 @@ static RC_FILTER_ATTR(wakeup_filter,
 S_IRUGO|S_IWUSR, static RC_FILTER_ATTR(wakeup_filter_mask, S_IRUGO|S_IWUSR,
 show_filter, store_filter, RC_FILTER_WAKEUP, true);
 
 -static struct attribute *rc_dev_attrs[] = {
 +static struct attribute *rc_dev_protocol_attrs[] = {
   dev_attr_protocols.attr.attr,
 + NULL,
 +};
 +
 +static struct attribute_group rc_dev_protocol_attr_grp = {
 + .attrs  = rc_dev_protocol_attrs

Re: [PATCH 05/11] rc-core: split dev-s_filter

2014-04-03 Thread James Hogan
Hi David,

On Saturday 29 March 2014 17:11:11 David Härdeman wrote:
 Overloading dev-s_filter to do two different functions (set wakeup filters
 and generic hardware filters) makes it impossible to tell what the
 hardware actually supports, so create a separate dev-s_wakeup_filter and
 make the distinction explicit.
 
 Signed-off-by: David Härdeman da...@hardeman.nu
 ---

 @@ -1121,9 +1126,11 @@ static ssize_t store_filter(struct device *device,
   if (ret  0)
   return ret;
 
 - /* Scancode filter not supported (but still accept 0) */
 - if (!dev-s_filter  fattr-type != RC_FILTER_NORMAL)
 - return val ? -EINVAL : count;
 + /* Can the scancode filter be set? */
 + set_filter = (fattr-type == RC_FILTER_NORMAL)
 + ? dev-s_filter : dev-s_wakeup_filter;
 + if (!set_filter)
 + return -EINVAL;

Technically the removal of the fattr-type != RC_FILTER_NORMAL condition and 
returning -EINVAL rather than val ? -EINVAL : count should be in patch 6 
since it's for generic scancode filter support.


 - if (dev-s_filter) {
 - ret = dev-s_filter(dev, fattr-type, local_filter);
 - if (ret  0)
 - goto unlock;
 - }
 +
 + ret = set_filter(dev, local_filter);
 + if (ret  0)
 + goto unlock;

same here for removing the if condition.

Otherwise this patch looks okay to me.

Cheers
James

signature.asc
Description: This is a digitally signed message part.


Re: [PATCH 04/11] rc-core: do not change 32bit NEC scancode format for now

2014-03-31 Thread James Hogan
On 29/03/14 16:11, David Härdeman wrote:
 This reverts 18bc17448147e93f31cc9b1a83be49f1224657b2
 
 The patch ignores the fact that NEC32 scancodes are generated not only in the
 NEC raw decoder but also directly in some drivers. Whichever approach is 
 chosen
 it should be consistent across drivers and this patch needs more discussion.
 
 Furthermore, I'm convinced that we have to stop playing games trying to
 decipher the meaning of NEC scancodes (what's the customer/vendor/address,
 which byte is the MSB, etc).
 
 This patch is in preparation for the next few patches in this series.
 
 Signed-off-by: David Härdeman da...@hardeman.nu
 ---
  drivers/media/rc/img-ir/img-ir-nec.c |   27 ++-
  drivers/media/rc/ir-nec-decoder.c|5 --
  drivers/media/rc/keymaps/rc-tivo.c   |   86 
 +-
  3 files changed, 59 insertions(+), 59 deletions(-)
 
 diff --git a/drivers/media/rc/img-ir/img-ir-nec.c 
 b/drivers/media/rc/img-ir/img-ir-nec.c
 index c0111d6..40ee844 100644
 --- a/drivers/media/rc/img-ir/img-ir-nec.c
 +++ b/drivers/media/rc/img-ir/img-ir-nec.c
 @@ -5,6 +5,7 @@
   */
  
  #include img-ir-hw.h
 +#include linux/bitrev.h
  
  /* Convert NEC data to a scancode */
  static int img_ir_nec_scancode(int len, u64 raw, enum rc_type *protocol,
 @@ -23,11 +24,11 @@ static int img_ir_nec_scancode(int len, u64 raw, enum 
 rc_type *protocol,
   data_inv = (raw  24)  0xff;
   if ((data_inv ^ data) != 0xff) {
   /* 32-bit NEC (used by Apple and TiVo remotes) */
 - /* scan encoding: aaAAddDD */
 - *scancode = addr_inv  24 |
 - addr  16 |
 - data_inv   8 |
 - data;
 + /* scan encoding: AAaaDDdd (LSBit first) */
 + *scancode = bitrev8(addr)  24 |
 + bitrev8(addr_inv)  16 |
 + bitrev8(data)   8 |
 + bitrev8(data_inv);
   } else if ((addr_inv ^ addr) != 0xff) {
   /* Extended NEC */
   /* scan encoding: AAaaDD */
 @@ -56,13 +57,15 @@ static int img_ir_nec_filter(const struct 
 rc_scancode_filter *in,
  
   if ((in-data | in-mask)  0xff00) {
   /* 32-bit NEC (used by Apple and TiVo remotes) */
 - /* scan encoding: aaAAddDD */
 - addr_inv   = (in-data  24)  0xff;
 - addr_inv_m = (in-mask  24)  0xff;
 - addr   = (in-data  16)  0xff;
 - addr_m = (in-mask  16)  0xff;
 - data_inv   = (in-data   8)  0xff;
 - data_inv_m = (in-mask   8)  0xff;
 + /* scan encoding: AAaaDDdd (LSBit first) */
 + addr   = bitrev8((in-data  24)  0xff);
 + addr_m = (in-mask  24)  0xff;
 + addr_inv   = bitrev8((in-data  16)  0xff);
 + addr_inv_m = (in-mask  16)  0xff;
 + data   = bitrev8((in-data   8)  0xff);
 + data_m = (in-mask   8)  0xff;
 + data_inv   = bitrev8((in-data   0)  0xff);
 + data_inv_m = (in-mask   0)  0xff;

I think the masks need bit reversing too, otherwise the mask bits won't
line up with the data as intended.

Otherwise this patch looks okay to me.

Cheers
James



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 06/11] rc-core: remove generic scancode filter

2014-03-31 Thread James Hogan
On 29/03/14 16:11, David Härdeman wrote:
 The generic scancode filtering has questionable value and makes it
 impossible to determine from userspace if there is an actual
 scancode hw filter present or not.
 
 So revert the generic parts.
 
 Based on a patch from James Hogan james.ho...@imgtec.com, but this
 version also makes sure that only the valid sysfs files are created
 in the first place.
 
 Signed-off-by: David Härdeman da...@hardeman.nu
 ---
  drivers/media/rc/rc-main.c |   66 
 +---
  include/media/rc-core.h|2 +
  2 files changed, 45 insertions(+), 23 deletions(-)
 
 diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
 index ba955ac..8675e07 100644
 --- a/drivers/media/rc/rc-main.c
 +++ b/drivers/media/rc/rc-main.c
 @@ -634,7 +634,6 @@ EXPORT_SYMBOL_GPL(rc_repeat);
  static void ir_do_keydown(struct rc_dev *dev, enum rc_type protocol,
 u32 scancode, u32 keycode, u8 toggle)
  {
 - struct rc_scancode_filter *filter;
   bool new_event = (!dev-keypressed   ||
 dev-last_protocol != protocol ||
 dev-last_scancode != scancode ||
 @@ -643,11 +642,6 @@ static void ir_do_keydown(struct rc_dev *dev, enum 
 rc_type protocol,
   if (new_event  dev-keypressed)
   ir_do_keyup(dev, false);
  
 - /* Generic scancode filtering */
 - filter = dev-scancode_filters[RC_FILTER_NORMAL];
 - if (filter-mask  ((scancode ^ filter-data)  filter-mask))
 - return;
 -
   input_event(dev-input_dev, EV_MSC, MSC_SCAN, scancode);
  
   if (new_event  keycode != KEY_RESERVED) {
 @@ -1017,14 +1011,11 @@ static ssize_t store_protocols(struct device *device,
   set_filter = (fattr-type == RC_FILTER_NORMAL)
   ? dev-s_filter : dev-s_wakeup_filter;
  
 - if (old_type != type  filter-mask) {
 + if (set_filter  old_type != type  filter-mask) {
   local_filter = *filter;
   if (!type) {
   /* no protocol = clear filter */
   ret = -1;
 - } else if (!set_filter) {
 - /* generic filtering = accept any filter */
 - ret = 0;
   } else {
   /* hardware filtering = try setting, otherwise clear */
   ret = set_filter(dev, local_filter);
 @@ -1033,8 +1024,7 @@ static ssize_t store_protocols(struct device *device,
   /* clear the filter */
   local_filter.data = 0;
   local_filter.mask = 0;
 - if (set_filter)
 - set_filter(dev, local_filter);
 + set_filter(dev, local_filter);
   }
  
   /* commit the new filter */
 @@ -1078,7 +1068,9 @@ static ssize_t show_filter(struct device *device,
   return -EINVAL;
  
   mutex_lock(dev-lock);
 - if (fattr-mask)
 + if (!dev-s_filter)
 + val = 0;

I suspect this should take s_wakeup_filter into account depending on
fattr-type. It's probably quite common to have a wakeup filter but no
normal filter.

The rest looks reasonable, though it could easily have been a separate
patch (at least as long as the show/store callbacks don't assume the
presence of the callbacks they use).

Cheers
James

 + else if (fattr-mask)
   val = dev-scancode_filters[fattr-type].mask;
   else
   val = dev-scancode_filters[fattr-type].data;
 @@ -1202,27 +1194,45 @@ static RC_FILTER_ATTR(wakeup_filter, S_IRUGO|S_IWUSR,
  static RC_FILTER_ATTR(wakeup_filter_mask, S_IRUGO|S_IWUSR,
 show_filter, store_filter, RC_FILTER_WAKEUP, true);
  
 -static struct attribute *rc_dev_attrs[] = {
 +static struct attribute *rc_dev_protocol_attrs[] = {
   dev_attr_protocols.attr.attr,
 + NULL,
 +};
 +
 +static struct attribute_group rc_dev_protocol_attr_grp = {
 + .attrs  = rc_dev_protocol_attrs,
 +};
 +
 +static struct attribute *rc_dev_wakeup_protocol_attrs[] = {
   dev_attr_wakeup_protocols.attr.attr,
 + NULL,
 +};
 +
 +static struct attribute_group rc_dev_wakeup_protocol_attr_grp = {
 + .attrs  = rc_dev_wakeup_protocol_attrs,
 +};
 +
 +static struct attribute *rc_dev_filter_attrs[] = {
   dev_attr_filter.attr.attr,
   dev_attr_filter_mask.attr.attr,
 - dev_attr_wakeup_filter.attr.attr,
 - dev_attr_wakeup_filter_mask.attr.attr,
   NULL,
  };
  
 -static struct attribute_group rc_dev_attr_grp = {
 - .attrs  = rc_dev_attrs,
 +static struct attribute_group rc_dev_filter_attr_grp = {
 + .attrs  = rc_dev_filter_attrs,
 +};
 +
 +static struct attribute *rc_dev_wakeup_filter_attrs[] = {
 + dev_attr_wakeup_filter.attr.attr,
 + dev_attr_wakeup_filter_mask.attr.attr,
 + NULL,
  };
  
 -static const struct attribute_group *rc_dev_attr_groups[] = {
 - rc_dev_attr_grp

Re: [PATCH 10/11] [RFC] rc-core: use the full 32 bits for NEC scancodes

2014-03-31 Thread James Hogan
On 29/03/14 16:11, David Härdeman wrote:
 Using the full 32 bits for all kinds of NEC scancodes simplifies rc-core
 and the nec decoder without any loss of functionality.
 
 In order to maintain backwards compatibility, some heuristics are added
 in rc-main.c to convert scancodes to NEC32 as necessary.
 
 I plan to introduce a different ioctl later which makes the protocol
 explicit (and which expects all NEC scancodes to be 32 bit, thereby
 removing the need for guesswork).
 
 Signed-off-by: David Härdeman da...@hardeman.nu
 ---
 diff --git a/drivers/media/rc/img-ir/img-ir-nec.c 
 b/drivers/media/rc/img-ir/img-ir-nec.c
 index 40ee844..133ea45 100644
 --- a/drivers/media/rc/img-ir/img-ir-nec.c
 +++ b/drivers/media/rc/img-ir/img-ir-nec.c
 @@ -5,42 +5,20 @@
   */
  
  #include img-ir-hw.h
 -#include linux/bitrev.h
  
  /* Convert NEC data to a scancode */
  static int img_ir_nec_scancode(int len, u64 raw, enum rc_type *protocol,
  u32 *scancode, u64 enabled_protocols)
  {
 - unsigned int addr, addr_inv, data, data_inv;
   /* a repeat code has no data */
   if (!len)
   return IMG_IR_REPEATCODE;
 +
   if (len != 32)
   return -EINVAL;
 - /* raw encoding: ddDDaaAA */
 - addr = (raw   0)  0xff;
 - addr_inv = (raw   8)  0xff;
 - data = (raw  16)  0xff;
 - data_inv = (raw  24)  0xff;
 - if ((data_inv ^ data) != 0xff) {
 - /* 32-bit NEC (used by Apple and TiVo remotes) */
 - /* scan encoding: AAaaDDdd (LSBit first) */
 - *scancode = bitrev8(addr)  24 |
 - bitrev8(addr_inv)  16 |
 - bitrev8(data)   8 |
 - bitrev8(data_inv);
 - } else if ((addr_inv ^ addr) != 0xff) {
 - /* Extended NEC */
 - /* scan encoding: AAaaDD */
 - *scancode = addr  16 |
 - addr_inv   8 |
 - data;
 - } else {
 - /* Normal NEC */
 - /* scan encoding: AADD */
 - *scancode = addr  8 |
 - data;
 - }
 +
 + /* raw encoding : ddDDaaAA - scan encoding: AAaaDDdd */
 + *scancode = swab32((u32)raw);

What's the point of the byte swapping?

Surely the most natural NEC encoding would just treat it as a single
32-bit (LSBit first) field rather than 4 8-bit fields that needs swapping.

Cheers
James



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 03/11] rc-core: document the protocol type

2014-03-31 Thread James Hogan
On 29/03/14 16:11, David Härdeman wrote:
 Right now the protocol information is not preserved, rc-core gets handed a
 scancode but has no idea which protocol it corresponds to.
 
 This patch (which required reading through the source/keymap for all drivers,
 not fun) makes the protocol information explicit which is important
 documentation and makes it easier to e.g. support multiple protocols with one
 decoder (think rc5 and rc-streamzap). The information isn't used yet so there
 should be no functional changes.
 
 Signed-off-by: David Härdeman da...@hardeman.nu

Good stuff. I very much approve of the concept, and had considered doing
the same thing myself.

Cheers
James



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 10/11] [RFC] rc-core: use the full 32 bits for NEC scancodes

2014-03-31 Thread James Hogan
On 31/03/14 11:19, David Härdeman wrote:
 On 2014-03-31 11:44, James Hogan wrote:
 On 29/03/14 16:11, David Härdeman wrote:
 Using the full 32 bits for all kinds of NEC scancodes simplifies rc-core
 and the nec decoder without any loss of functionality.

 In order to maintain backwards compatibility, some heuristics are added
 in rc-main.c to convert scancodes to NEC32 as necessary.

 I plan to introduce a different ioctl later which makes the protocol
 explicit (and which expects all NEC scancodes to be 32 bit, thereby
 removing the need for guesswork).

 Signed-off-by: David Härdeman da...@hardeman.nu
 ---
 diff --git a/drivers/media/rc/img-ir/img-ir-nec.c
 b/drivers/media/rc/img-ir/img-ir-nec.c
 index 40ee844..133ea45 100644
 --- a/drivers/media/rc/img-ir/img-ir-nec.c
 +++ b/drivers/media/rc/img-ir/img-ir-nec.c
 @@ -5,42 +5,20 @@
   */

  #include img-ir-hw.h
 -#include linux/bitrev.h

  /* Convert NEC data to a scancode */
  static int img_ir_nec_scancode(int len, u64 raw, enum rc_type
 *protocol,
 u32 *scancode, u64 enabled_protocols)
  {
 -unsigned int addr, addr_inv, data, data_inv;
  /* a repeat code has no data */
  if (!len)
  return IMG_IR_REPEATCODE;
 +
  if (len != 32)
  return -EINVAL;
 -/* raw encoding: ddDDaaAA */
 -addr = (raw   0)  0xff;
 -addr_inv = (raw   8)  0xff;
 -data = (raw  16)  0xff;
 -data_inv = (raw  24)  0xff;
 -if ((data_inv ^ data) != 0xff) {
 -/* 32-bit NEC (used by Apple and TiVo remotes) */
 -/* scan encoding: AAaaDDdd (LSBit first) */
 -*scancode = bitrev8(addr)  24 |
 -bitrev8(addr_inv)  16 |
 -bitrev8(data)   8 |
 -bitrev8(data_inv);
 -} else if ((addr_inv ^ addr) != 0xff) {
 -/* Extended NEC */
 -/* scan encoding: AAaaDD */
 -*scancode = addr  16 |
 -addr_inv   8 |
 -data;
 -} else {
 -/* Normal NEC */
 -/* scan encoding: AADD */
 -*scancode = addr  8 |
 -data;
 -}
 +
 +/* raw encoding : ddDDaaAA - scan encoding: AAaaDDdd */
 +*scancode = swab32((u32)raw);

 What's the point of the byte swapping?

 Surely the most natural NEC encoding would just treat it as a single
 32-bit (LSBit first) field rather than 4 8-bit fields that needs
 swapping.
 
 Thanks for having a look at the patches, I agree with your comments on
 the other patches (and I have to respin some of them because I missed
 two drivers), but the comments to this patch confuses me a bit.
 
 That the NEC data is transmitted as 32 bits encoded with LSB bit order
 within each byte is AFAIK just about the only thing that all
 sources/documentation of the protocal can agree on (so bitrev:ing the
 bits within each byte makes sense, unless the hardware has done it
 already).

Agreed (in the case of img-ir there's a bit orientation setting which
ensures that the u64 raw has the correct bit order, in the case of NEC
the first bit received goes in the lowest order bit of the raw data).

 As for the byte order, AAaaDDdd corresponds to the transmission order
 and seems to be what most drivers expect/use for their RX data.

AAaaDDdd is big endian rendering, no? (like %08x)

If it should be interpreted as LSBit first, then the first bits received
should go in the low bits of the scancode, and by extension the first
bytes received in the low bytes of the scancode, i.e. at the end of the
inherently big-endian hexadecimal rendering of the scancode.

 Are you suggesting that rc-core should standardize on ddDDaaAA order?

Yes (where ddDDaaAA means something like scancode
0x(~cmd)(cmd)(~addr)(addr))

This would mean that if the data is put in the right bit order (first
bit received in BIT(0), last bit received in BIT(31)), then the scancode
= raw, and if the data is received in the reverse bit order (like the
raw decoder, shifting the data left and inserting the last bit in
BIT(0)) then the scancode = bitrev32(raw).

Have I missed something?

Cheers
James



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 10/11] [RFC] rc-core: use the full 32 bits for NEC scancodes

2014-03-31 Thread James Hogan
On 31/03/14 14:22, David Härdeman wrote:
 On 2014-03-31 12:56, James Hogan wrote:
 This would mean that if the data is put in the right bit order (first
 bit received in BIT(0), last bit received in BIT(31)), then the scancode
 = raw, and if the data is received in the reverse bit order (like the
 raw decoder, shifting the data left and inserting the last bit in
 BIT(0)) then the scancode = bitrev32(raw).

 Have I missed something?
 
 I just think we have to agree to disagree :)
 
 For me, storing/presenting the scancode as 0xAAaaDDdd is obviously the
 clearest and least confusing interpretation. But I might have spent too
 long time using that notation in code and mentally to be able to find
 anything else intuitive :)
 
 0xAAaaDDdd means that you read/parse/print it left to right, just as you
 would if you drew a pulse-space chart showing the received IR pulse
 (time normally progresses to the right...modulo the per-byte bitrev).

Sure, but the NEC bit order is little endian, and the scancode is a
32bit value not an array of 4 bytes, so it's artificial to expect it to
make any sense when read as big endian. E.g. if you extended the
transmission to 48 bits you'd expect the hex printed scancode to extend
to the left not the right.

The bits in the 32-bit word also become discontinuous for no good
reason, especially considering the cases we're trying to take into
account (NEC-32 and NEC-24) both effectively have 16-bit fields.

 It kind of matches the other protocol scancodes as well (the address
 bits high, cmd bits low, the high bits tend to remain constant for one
 given remote, the low bits change, although it's not a hard rule) and it

Very true, but you still have the low byte of the command in the 2nd
lowest byte, which is why my original suggestion was:
0xaaAAddDD

I.e. swap 16bit halves, each 16bit field intact.

 matches most software I've ever seen (AFAIK, LIRC represents NEC32
 scancodes this way, as does e.g. the Pronto software and protocol).
 
 That said...I think we at least agree that we need *a* representation
 and that it should be used consistently in all drivers, right?

Yes, that would be nice.

Cheers
James



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 06/11] rc-core: remove generic scancode filter

2014-03-31 Thread James Hogan
On Monday 31 March 2014 21:38:13 David Härdeman wrote:
 The rest looks reasonable, though it could easily have been a separate
 patch (at least as long as the show/store callbacks don't assume the
 presence of the callbacks they use).
 
 Yes, I wanted to avoid there being more intermediary states than
 necessary (i.e. first a read/writable sysfs file, then one that can't be
 read/written, then the file disappears...).

Fair enough

 Can still respin it on top of your patch if you prefer.

It doesn't particularly bother me tbh, so do what you think is best.

Cheers
James

signature.asc
Description: This is a digitally signed message part.


Re: [PATCH] rc-core: do not change 32bit NEC scancode format for now

2014-03-28 Thread James Hogan
On Friday 28 March 2014 01:08:56 David Härdeman wrote:
 On Thu, Mar 27, 2014 at 11:21:23PM +, James Hogan wrote:
 Hi David,
 
 On Thursday 27 March 2014 22:00:37 David Härdeman wrote:
  This reverts 18bc17448147e93f31cc9b1a83be49f1224657b2
  
  The patch ignores the fact that NEC32 scancodes are generated not only in
  the NEC raw decoder but also directly in some drivers. Whichever approach
  is chosen it should be consistent across drivers and this patch needs
  more
  discussion.
 
 Fair enough. For reference which drivers are you referring to?
 
 The ones I'm aware of right now are:

Thanks, I hadn't looked properly outside of drivers/media/rc/ :(

 drivers/media/usb/dvb-usb/dib0700_core.c

AFAICT this only seems to support 16bit and 24bit NEC, so NEC-32 doesn't affect 
it. I may have missed something subtle.

 drivers/media/usb/dvb-usb-v2/az6007.c
 drivers/media/usb/dvb-usb-v2/af9035.c
 drivers/media/usb/dvb-usb-v2/rtl28xxu.c
 drivers/media/usb/dvb-usb-v2/af9015.c
 drivers/media/usb/em28xx/em28xx-input.c

Note, it appears none of these do any bit reversing for the 32bit case 
compared to 16/24 bit, so they're already different to the NEC32 scancode 
encoding that the raw nec decoder and tivo keymap were using, which used a 
different bitorder (!!) between the 32-bit and the 24/16-bit cases.

 
  Furthermore, I'm convinced that we have to stop playing games trying to
  decipher the meaning of NEC scancodes (what's the
  customer/vendor/address, which byte is the MSB, etc).
 
 Well when all the buttons on a remote have the same address, and the
 numeric buttons are sequential commands only in a certain bit/byte order,
 then I think the word decipher is probably a bit of a stretch.
 
 I think you misunderstood me. decipher is a bit of a stretch when
 talking of one remote control (I'm guessing you're referring to the Tivo
 remote). It's not that much of a stretch if we're referring to trying to
 derive a common meaning from the encoding used for *all* remote controls
 out there.
 
 The discussion about the 24-bit version of NEC and whether the address
 bytes were in MSB or LSB order was a good example. Andy Walls cited a
 NEC manual which stated one thing and people also referred to
 http://www.sbprojects.com/knowledge/ir/nec.php which stated the opposite
 (while referring to an unnamed VCR service manual).
 
 As a third example...I've read a Samsung service manual which happily
 stated that the remote (which used the NEC protocol) sent IR commands
 starting with the address x 2 (and looking at the raw NEC command, it
 did start with something like 0x07 0x07).
 
 So don't get me wrong, I wasn't referring to your analysis of the Tivo
 remote but more the general approach that has been taken until now wrt.
 the NEC protocol in the kernel drivers.

Okay, thanks for the clarification.

 
 Nevertheless I don't have any attachment to 32-bit NEC. If it's likely to
 change again I'd prefer img-ir-nec just not support it for now, so please
 could you add the following hunks to your patch (or if the original patch
 is
 to be dropped this could be squashed into the img-ir-nec patch):
 I'd rather show you my complete proposal first before doing something
 radical with your driver. But it was a good reminder that I need to keep
 the NEC32 parsing in your driver in mind as well.

Okay no problem. I had assumed you were aiming for a short term fix to prevent 
the encoding change hitting mainline or an actual release (v3.15).

Cheers
James

 
  I'll post separate proposals to that effect later.
 
 Great, please do Cc me
 
 (I have a work in progress branch to unify NEC scancodes, but I'm not sure
 I'd have time to complete it any time soon anyway)
 
 That is what I'm working on as well at the moment. It's actually to
 solve two problems...both to unify NEC scancodes (by simply using 32 bit
 scancodes everywhere and some fallback code...I'm not 100% sure it's
 doable but I hope so since it's the only sane solution I can think of in
 the long run)...and to make sure that protocol information actually gets
 used in keymaps, etc.
 
 I hope to post patches soon that'll make it clearer.
 
 Regards,
 David
 
 --
 To unsubscribe from this list: send the line unsubscribe linux-media in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html


signature.asc
Description: This is a digitally signed message part.


Re: [PATCH] rc-core: do not change 32bit NEC scancode format for now

2014-03-27 Thread James Hogan
Hi David,

On Thursday 27 March 2014 22:00:37 David Härdeman wrote:
 This reverts 18bc17448147e93f31cc9b1a83be49f1224657b2
 
 The patch ignores the fact that NEC32 scancodes are generated not only in
 the NEC raw decoder but also directly in some drivers. Whichever approach
 is chosen it should be consistent across drivers and this patch needs more
 discussion.

Fair enough. For reference which drivers are you referring to?

 Furthermore, I'm convinced that we have to stop playing games trying to
 decipher the meaning of NEC scancodes (what's the customer/vendor/address,
 which byte is the MSB, etc).

Well when all the buttons on a remote have the same address, and the numeric
buttons are sequential commands only in a certain bit/byte order, then I think
the word decipher is probably a bit of a stretch.

Nevertheless I don't have any attachment to 32-bit NEC. If it's likely to
change again I'd prefer img-ir-nec just not support it for now, so please
could you add the following hunks to your patch (or if the original patch is
to be dropped this could be squashed into the img-ir-nec patch):

diff --git a/drivers/media/rc/img-ir/img-ir-nec.c 
b/drivers/media/rc/img-ir/img-ir-nec.c
index e7a731b..419d087 100644
--- a/drivers/media/rc/img-ir/img-ir-nec.c
+++ b/drivers/media/rc/img-ir/img-ir-nec.c
@@ -21,12 +21,7 @@ static int img_ir_nec_scancode(int len, u64 raw, int 
*scancode, u64 protocols)
data = (raw  16)  0xff;
data_inv = (raw  24)  0xff;
if ((data_inv ^ data) != 0xff) {
-   /* 32-bit NEC (used by Apple and TiVo remotes) */
-   /* scan encoding: aaAAddDD */
-   *scancode = addr_inv  24 |
-   addr  16 |
-   data_inv   8 |
-   data;
+   return -EINVAL;
} else if ((addr_inv ^ addr) != 0xff) {
/* Extended NEC */
/* scan encoding: AAaaDD */
@@ -53,14 +48,7 @@ static int img_ir_nec_filter(const struct rc_scancode_filter 
*in,
data_m = in-mask  0xff;
 
if ((in-data | in-mask)  0xff00) {
-   /* 32-bit NEC (used by Apple and TiVo remotes) */
-   /* scan encoding: aaAAddDD */
-   addr_inv   = (in-data  24)  0xff;
-   addr_inv_m = (in-mask  24)  0xff;
-   addr   = (in-data  16)  0xff;
-   addr_m = (in-mask  16)  0xff;
-   data_inv   = (in-data   8)  0xff;
-   data_inv_m = (in-mask   8)  0xff;
+   return -EINVAL;
} else if ((in-data | in-mask)  0x00ff) {
/* Extended NEC */
/* scan encoding AAaaDD */


 
 I'll post separate proposals to that effect later.

Great, please do Cc me

(I have a work in progress branch to unify NEC scancodes, but I'm not sure
I'd have time to complete it any time soon anyway)

Thanks
James

 
 Signed-off-by: David Härdeman da...@hardeman.nu
 ---
  drivers/media/rc/ir-nec-decoder.c  |5 --
  drivers/media/rc/keymaps/rc-tivo.c |   86
 ++-- 2 files changed, 44 insertions(+), 47
 deletions(-)
 
 diff --git a/drivers/media/rc/ir-nec-decoder.c
 b/drivers/media/rc/ir-nec-decoder.c index 735a509..c4333d5 100644
 --- a/drivers/media/rc/ir-nec-decoder.c
 +++ b/drivers/media/rc/ir-nec-decoder.c
 @@ -172,10 +172,7 @@ static int ir_nec_decode(struct rc_dev *dev, struct
 ir_raw_event ev) if (send_32bits) {
   /* NEC transport, but modified protocol, used by at
* least Apple and TiVo remotes */
 - scancode = not_address  24 |
 -address  16 |
 -not_command   8 |
 -command;
 + scancode = data-bits;
   IR_dprintk(1, NEC (modified) scancode 0x%08x\n, 
 scancode);
   } else if ((address ^ not_address) != 0xff) {
   /* Extended NEC */
 diff --git a/drivers/media/rc/keymaps/rc-tivo.c
 b/drivers/media/rc/keymaps/rc-tivo.c index 5cc1b45..454e062 100644
 --- a/drivers/media/rc/keymaps/rc-tivo.c
 +++ b/drivers/media/rc/keymaps/rc-tivo.c
 @@ -15,62 +15,62 @@
   * Initial mapping is for the TiVo remote included in the Nero LiquidTV
 bundle, * which also ships with a TiVo-branded IR transceiver, supported by
 the mceusb * driver. Note that the remote uses an NEC-ish protocol, but
 instead of having - * a command/not_command pair, it has a vendor ID of
 0x3085, but some keys, the + * a command/not_command pair, it has a vendor
 ID of 0xa10c, but some keys, the * NEC extended checksums do pass, so the
 table presently has the intended * values and the checksum-passed versions
 for those keys.
   */
  static struct rc_map_table tivo[] = {
 - { 0x3085f009, KEY_MEDIA },  /* TiVo Button */
 - { 0x3085e010, KEY_POWER2 }, /* TV Power */
 - { 0x3085e011, KEY_TV }, 

Re: [PATCH v4 00/10] media: rc: ImgTec IR decoder driver

2014-03-26 Thread James Hogan
On 25/03/14 23:53, David Härdeman wrote:
 On Fri, Feb 28, 2014 at 11:28:50PM +, James Hogan wrote:
 Add a driver for the ImgTec Infrared decoder block. Two separate rc
 input devices are exposed depending on kernel configuration. One uses
 the hardware decoder which is set up with timings for a specific
 protocol and supports mask/value filtering and wake events. The other
 uses raw edge interrupts and the generic software protocol decoders to
 allow multiple protocols to be supported, including those not supported
 by the hardware decoder.
 
 One thing I just noticed...your copyright headers throughout the driver
 seems a bit...sparse? :)

True, I can add the basic:

 * 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.

to each of the files if you think it's necessary.

Cheers
James



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 1/5] rc-main: add generic scancode filtering

2014-03-26 Thread James Hogan
On 26/03/14 13:44, David Härdeman wrote:
 On 2014-03-26 08:08, Antti Seppälä wrote:
 On 26 March 2014 01:21, David Härdeman da...@hardeman.nu wrote:
 On Tue, Mar 25, 2014 at 09:12:11AM +, James Hogan wrote:
 On Tuesday 25 March 2014 00:51:46 David Härdeman wrote:
 What's the purpose of providing the sw scancode filtering in the
 case where
 there's no hardware filtering support at all?

 Consistency is probably the main reason, but I'll admit it's not
 perfectly
 consistent between generic/hardware filtering (mostly thanks to NEC
 scancode
 complexities), and I have no particular objection to dropping it if
 that isn't
 considered a good enough reason.

 I'm kind of sceptical...and given how difficult it is to remove
 functionality that is in a released kernel...I think that particular
 part (i.e. the software filtering) should be removed until it has had
 further discussion...
 ...
 I don't understand. What's the purpose of a software fallback for
 scancode filtering? Antti?


 Well since the ImgTec patches will create a new sysfs interface for
 the HW scancode filtering I figured that it would be nice for it to
 also function on devices which lack the hardware filtering
 capabilities. Especially since it's only three lines of code. :)

 Therefore I suggested the software fallback. At the time I had no clue
 that there might be added complexities with nec scancodes.
 
 It's not only NEC scancodes, the sw scancode filter is state that is
 changeable from user-space and which will require reader/writer
 synchronization during the RX path (which is the hottest path in
 rc-core). I've posted patches before which make the RX path lockless,
 this change makes complicates such changes.
 
 Additionally, the provision of the sw fallback means that userspace has
 no idea if there is an actual hardware filter present or not, meaning
 that a userspace program that is aware of the scancode filter will
 always enable it.
 
 So, I still think the SW part should be reverted, at least for now (i.e.
 the sysfs file should only be present if there is hardware support).

I've prepared a revert patch (which also reverts a part of a later patch
which takes SW filtering into account when updating the filter on a
protocol change). I'll double check it works right later and submit.

Note that this still leaves the sysfs nodes there though, but if
!s_filter then they read as 0 and only accept the value 0 to be written
(mask == 0 represents no filtering).

Cheers
James



signature.asc
Description: OpenPGP digital signature


[PATCH 0/3] rc: Misc fixes for v3.15

2014-03-26 Thread James Hogan
A few misc fixes for v3.15, all relating to my previous patches.

James Hogan (3):
  rc-main: Revert generic scancode filtering support
  rc-main: Limit to a single wakeup protocol group
  rc: img-ir: Expand copyright headers with GPL notices

 drivers/media/rc/img-ir/img-ir-core.c  |  5 +
 drivers/media/rc/img-ir/img-ir-hw.c|  5 +
 drivers/media/rc/img-ir/img-ir-hw.h|  5 +
 drivers/media/rc/img-ir/img-ir-jvc.c   |  5 +
 drivers/media/rc/img-ir/img-ir-nec.c   |  5 +
 drivers/media/rc/img-ir/img-ir-raw.c   |  5 +
 drivers/media/rc/img-ir/img-ir-raw.h   |  5 +
 drivers/media/rc/img-ir/img-ir-sanyo.c |  5 +
 drivers/media/rc/img-ir/img-ir-sharp.c |  5 +
 drivers/media/rc/img-ir/img-ir-sony.c  |  5 +
 drivers/media/rc/img-ir/img-ir.h   |  5 +
 drivers/media/rc/rc-main.c | 39 ++
 12 files changed, 76 insertions(+), 18 deletions(-)

Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: David Härdeman da...@hardeman.nu
Cc: Antti Seppälä a.sepp...@gmail.com
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/3] rc-main: Revert generic scancode filtering support

2014-03-26 Thread James Hogan
This reverts commit b8c7d915087c ([media] rc-main: add generic scancode
filtering), and removes certain parts of commit 6bea25af147f ([media]
rc-main: automatically refresh filter on protocol change) where generic
filtering is taken into account when refreshing filters on a protocol
change, but that code cannot be reached any longer since the filter mask
will always be zero if the s_filter callback is NULL.

Generic scancode filtering had questionable value and as David said:
 given how difficult it is to remove functionality that is in a
 released kernel...I think that particular part (i.e. the software
 filtering) should be removed until it has had further discussion.

Reported-by: David Härdeman da...@hardeman.nu
Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: David Härdeman da...@hardeman.nu
Cc: Antti Seppälä a.sepp...@gmail.com
---
 drivers/media/rc/rc-main.c | 26 --
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 99697aa..e067fee 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -633,7 +633,6 @@ EXPORT_SYMBOL_GPL(rc_repeat);
 static void ir_do_keydown(struct rc_dev *dev, int scancode,
  u32 keycode, u8 toggle)
 {
-   struct rc_scancode_filter *filter;
bool new_event = !dev-keypressed ||
 dev-last_scancode != scancode ||
 dev-last_toggle != toggle;
@@ -641,11 +640,6 @@ static void ir_do_keydown(struct rc_dev *dev, int scancode,
if (new_event  dev-keypressed)
ir_do_keyup(dev, false);
 
-   /* Generic scancode filtering */
-   filter = dev-scancode_filters[RC_FILTER_NORMAL];
-   if (filter-mask  ((scancode ^ filter-data)  filter-mask))
-   return;
-
input_event(dev-input_dev, EV_MSC, MSC_SCAN, scancode);
 
if (new_event  keycode != KEY_RESERVED) {
@@ -1012,9 +1006,6 @@ static ssize_t store_protocols(struct device *device,
if (!type) {
/* no protocol = clear filter */
ret = -1;
-   } else if (!dev-s_filter) {
-   /* generic filtering = accept any filter */
-   ret = 0;
} else {
/* hardware filtering = try setting, otherwise clear */
ret = dev-s_filter(dev, fattr-type, local_filter);
@@ -1023,8 +1014,7 @@ static ssize_t store_protocols(struct device *device,
/* clear the filter */
local_filter.data = 0;
local_filter.mask = 0;
-   if (dev-s_filter)
-   dev-s_filter(dev, fattr-type, local_filter);
+   dev-s_filter(dev, fattr-type, local_filter);
}
 
/* commit the new filter */
@@ -1068,7 +1058,9 @@ static ssize_t show_filter(struct device *device,
return -EINVAL;
 
mutex_lock(dev-lock);
-   if (fattr-mask)
+   if (!dev-s_filter)
+   val = 0;
+   else if (fattr-mask)
val = dev-scancode_filters[fattr-type].mask;
else
val = dev-scancode_filters[fattr-type].data;
@@ -1116,7 +1108,7 @@ static ssize_t store_filter(struct device *device,
return ret;
 
/* Scancode filter not supported (but still accept 0) */
-   if (!dev-s_filter  fattr-type != RC_FILTER_NORMAL)
+   if (!dev-s_filter)
return val ? -EINVAL : count;
 
mutex_lock(dev-lock);
@@ -1133,11 +1125,9 @@ static ssize_t store_filter(struct device *device,
ret = -EINVAL;
goto unlock;
}
-   if (dev-s_filter) {
-   ret = dev-s_filter(dev, fattr-type, local_filter);
-   if (ret  0)
-   goto unlock;
-   }
+   ret = dev-s_filter(dev, fattr-type, local_filter);
+   if (ret  0)
+   goto unlock;
 
/* Success, commit the new filter */
*filter = local_filter;
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/3] rc: img-ir: Expand copyright headers with GPL notices

2014-03-26 Thread James Hogan
Add the basic GPLv2+ license notice to the copyright headers at the top
of all the source files in the img-ir driver.

Reported-by: David Härdeman da...@hardeman.nu
Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: David Härdeman da...@hardeman.nu
---
 drivers/media/rc/img-ir/img-ir-core.c  | 5 +
 drivers/media/rc/img-ir/img-ir-hw.c| 5 +
 drivers/media/rc/img-ir/img-ir-hw.h| 5 +
 drivers/media/rc/img-ir/img-ir-jvc.c   | 5 +
 drivers/media/rc/img-ir/img-ir-nec.c   | 5 +
 drivers/media/rc/img-ir/img-ir-raw.c   | 5 +
 drivers/media/rc/img-ir/img-ir-raw.h   | 5 +
 drivers/media/rc/img-ir/img-ir-sanyo.c | 5 +
 drivers/media/rc/img-ir/img-ir-sharp.c | 5 +
 drivers/media/rc/img-ir/img-ir-sony.c  | 5 +
 drivers/media/rc/img-ir/img-ir.h   | 5 +
 11 files changed, 55 insertions(+)

diff --git a/drivers/media/rc/img-ir/img-ir-core.c 
b/drivers/media/rc/img-ir/img-ir-core.c
index 6b78348..a0cac2f 100644
--- a/drivers/media/rc/img-ir/img-ir-core.c
+++ b/drivers/media/rc/img-ir/img-ir-core.c
@@ -3,6 +3,11 @@
  *
  * Copyright 2010-2014 Imagination Technologies Ltd.
  *
+ * 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 contains core img-ir code for setting up the driver. The two interfaces
  * (raw and hardware decode) are handled separately.
  */
diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
b/drivers/media/rc/img-ir/img-ir-hw.c
index 579a52b..23b47c7 100644
--- a/drivers/media/rc/img-ir/img-ir-hw.c
+++ b/drivers/media/rc/img-ir/img-ir-hw.c
@@ -3,6 +3,11 @@
  *
  * Copyright 2010-2014 Imagination Technologies Ltd.
  *
+ * 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 ties into the input subsystem using the RC-core. Protocol support is
  * provided in separate modules which provide the parameters and scancode
  * translation functions to set up the hardware decoder and interpret the
diff --git a/drivers/media/rc/img-ir/img-ir-hw.h 
b/drivers/media/rc/img-ir/img-ir-hw.h
index 6c9a94a..450f17d 100644
--- a/drivers/media/rc/img-ir/img-ir-hw.h
+++ b/drivers/media/rc/img-ir/img-ir-hw.h
@@ -2,6 +2,11 @@
  * ImgTec IR Hardware Decoder found in PowerDown Controller.
  *
  * Copyright 2010-2014 Imagination Technologies Ltd.
+ *
+ * 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.
  */
 
 #ifndef _IMG_IR_HW_H_
diff --git a/drivers/media/rc/img-ir/img-ir-jvc.c 
b/drivers/media/rc/img-ir/img-ir-jvc.c
index 10209d2..85ee90f 100644
--- a/drivers/media/rc/img-ir/img-ir-jvc.c
+++ b/drivers/media/rc/img-ir/img-ir-jvc.c
@@ -2,6 +2,11 @@
  * ImgTec IR Decoder setup for JVC protocol.
  *
  * Copyright 2012-2014 Imagination Technologies Ltd.
+ *
+ * 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.
  */
 
 #include img-ir-hw.h
diff --git a/drivers/media/rc/img-ir/img-ir-nec.c 
b/drivers/media/rc/img-ir/img-ir-nec.c
index e7a731b..cff3212 100644
--- a/drivers/media/rc/img-ir/img-ir-nec.c
+++ b/drivers/media/rc/img-ir/img-ir-nec.c
@@ -2,6 +2,11 @@
  * ImgTec IR Decoder setup for NEC protocol.
  *
  * Copyright 2010-2014 Imagination Technologies Ltd.
+ *
+ * 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.
  */
 
 #include img-ir-hw.h
diff --git a/drivers/media/rc/img-ir/img-ir-raw.c 
b/drivers/media/rc/img-ir/img-ir-raw.c
index cfb01d9..33f37ed 100644
--- a/drivers/media/rc/img-ir/img-ir-raw.c
+++ b/drivers/media/rc/img-ir/img-ir-raw.c
@@ -3,6 +3,11 @@
  *
  * Copyright 2010-2014 Imagination Technologies Ltd.
  *
+ * 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 ties into the input subsystem using the RC-core in raw mode. Raw IR
  * signal edges are reported and decoded by generic software decoders.
  */
diff --git a/drivers/media/rc/img-ir/img-ir-raw.h 
b/drivers/media/rc/img-ir/img-ir-raw.h

[PATCH 2/3] rc-main: Limit to a single wakeup protocol group

2014-03-26 Thread James Hogan
Limit the enabled wakeup protocols to be within a protocol group, as
defined by the proto_names array. For example this prevents the
selection of both rc-5 and nec, while allowing rc-5 alone (which
encompasses both normal rc-5 and rc-5x).

It doesn't usually make sense to enable more than one wakeup protocol
since only a single protocol can usually be used for wakeup at a time,
and doing so with encode based wakeup will result in an arbitrary
protocol being used if multiple are possible.

Reported-by: Antti Seppälä a.sepp...@gmail.com
Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Antti Seppälä a.sepp...@gmail.com
---
Sorry it took a little while to get around to submitting this.
---
 drivers/media/rc/rc-main.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index e067fee..79d1060 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -979,6 +979,19 @@ static ssize_t store_protocols(struct device *device,
goto out;
}
 
+   if (fattr-type == RC_FILTER_WAKEUP) {
+   /* A proto_names entry must cover enabled wakeup protocols */
+   for (i = 0; i  ARRAY_SIZE(proto_names); i++)
+   if (type  proto_names[i].type 
+   !(type  ~proto_names[i].type))
+   break;
+   if (i == ARRAY_SIZE(proto_names)) {
+   IR_dprintk(1, Multiple distinct wakeup protocols\n);
+   ret = -EINVAL;
+   goto out;
+   }
+   }
+
change_protocol = (fattr-type == RC_FILTER_NORMAL)
? dev-change_protocol : dev-change_wakeup_protocol;
if (change_protocol) {
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/5] rc-main: add generic scancode filtering

2014-03-25 Thread James Hogan
On Tuesday 25 March 2014 00:51:46 David Härdeman wrote:
 On Fri, Feb 28, 2014 at 11:17:02PM +, James Hogan wrote:
 Add generic scancode filtering of RC input events, and fall back to
 permitting any RC_FILTER_NORMAL scancode filter to be set if no s_filter
 callback exists. This allows raw IR decoder events to be filtered, and
 potentially allows hardware decoders to set looser filters and rely on
 generic code to filter out the corner cases.
 
 Hi James,
 
 What's the purpose of providing the sw scancode filtering in the case where
 there's no hardware filtering support at all?

Consistency is probably the main reason, but I'll admit it's not perfectly 
consistent between generic/hardware filtering (mostly thanks to NEC scancode 
complexities), and I have no particular objection to dropping it if that isn't 
considered a good enough reason.

Here's the original discussion:
On Monday 10 February 2014 21:45:30 Antti Seppälä wrote:
 On 10 February 2014 11:58, James Hogan james.ho...@imgtec.com wrote:
  On Saturday 08 February 2014 13:30:01 Antti Seppälä wrote:
   Also adding the scancode filter to it would
   demonstrate its usage.
  
  To actually add filtering support to loopback would require either:
  * raw-decoder/rc-core level scancode filtering for raw ir drivers
  * OR loopback driver to encode like nuvoton and fuzzy match the IR
  signals.
 
 Rc-core level scancode filtering shouldn't be too hard to do right? If
 such would exist then it would provide a software fallback to other rc
 devices where hardware filtering isn't available. I'd love to see the
 sysfs filter and filter_mask files to have an effect on my nuvoton too


 (sorry that I'm replying so late...busy schedule :))

No problem :)

Cheers
James

 Signed-off-by: James Hogan james.ho...@imgtec.com
 Cc: Mauro Carvalho Chehab m.che...@samsung.com
 Cc: Antti Seppälä a.sepp...@gmail.com
 Cc: linux-media@vger.kernel.org
 ---
 
  drivers/media/rc/rc-main.c | 20 +---
  1 file changed, 13 insertions(+), 7 deletions(-)
 
 diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
 index 6448128..0a4f680 100644
 --- a/drivers/media/rc/rc-main.c
 +++ b/drivers/media/rc/rc-main.c
 @@ -633,6 +633,7 @@ EXPORT_SYMBOL_GPL(rc_repeat);
 
  static void ir_do_keydown(struct rc_dev *dev, int scancode,
  
u32 keycode, u8 toggle)
  
  {
 
 +struct rc_scancode_filter *filter;
 
  bool new_event = !dev-keypressed ||
  
   dev-last_scancode != scancode ||
   dev-last_toggle != toggle;
 
 @@ -640,6 +641,11 @@ static void ir_do_keydown(struct rc_dev *dev, int
 scancode,
  if (new_event  dev-keypressed)
  
  ir_do_keyup(dev, false);
 
 +/* Generic scancode filtering */
 +filter = dev-scancode_filters[RC_FILTER_NORMAL];
 +if (filter-mask  ((scancode ^ filter-data)  filter-mask))
 +return;
 +
 
  input_event(dev-input_dev, EV_MSC, MSC_SCAN, scancode);
  
  if (new_event  keycode != KEY_RESERVED) {
 
 @@ -1019,9 +1025,7 @@ static ssize_t show_filter(struct device *device,
 
  return -EINVAL;
  
  mutex_lock(dev-lock);
 
 -if (!dev-s_filter)
 -val = 0;
 -else if (fattr-mask)
 +if (fattr-mask)
 
  val = dev-scancode_filters[fattr-type].mask;
  
  else
  
  val = dev-scancode_filters[fattr-type].data;
 
 @@ -1069,7 +1073,7 @@ static ssize_t store_filter(struct device *device,
 
  return ret;
  
  /* Scancode filter not supported (but still accept 0) */
 
 -if (!dev-s_filter)
 +if (!dev-s_filter  fattr-type != RC_FILTER_NORMAL)
 
  return val ? -EINVAL : count;
  
  mutex_lock(dev-lock);
 
 @@ -1081,9 +1085,11 @@ static ssize_t store_filter(struct device *device,
 
  local_filter.mask = val;
  
  else
  
  local_filter.data = val;
 
 -ret = dev-s_filter(dev, fattr-type, local_filter);
 -if (ret  0)
 -goto unlock;
 +if (dev-s_filter) {
 +ret = dev-s_filter(dev, fattr-type, local_filter);
 +if (ret  0)
 +goto unlock;
 +}
 
  /* Success, commit the new filter */
  *filter = local_filter;


signature.asc
Description: This is a digitally signed message part.


Re: [PATCH v2 0/9] rc: Add IR encode based wakeup filtering

2014-03-17 Thread James Hogan
On Monday 17 March 2014 19:01:51 Antti Seppälä wrote:
 On 17 March 2014 00:41, James Hogan ja...@albanarts.com wrote:
  Yeh I'm in two minds about this now. It's actually a little awkward since
  some of the protocols have multiple variants (i.e. rc-5 = RC5+RC5X),
  but an encoded message is only ever a single variant, so technically if
  you're going to draw the line for wakeup protocols it should probably be
  at one enabled variant, which isn't always convenient or necessary.
 
 I'd very much prefer to have the selector as it currently is -
 protocol groups instead of variants which would keep it consistent
 with decoding protocol selection.

Yeh, I'll submit a patch to fix wakeup-protocols to disallow multiple groups 
of protocols from being enabled at the same time.

  Note, ATM even disallowing +proto and -proto we would already have to
  guess which variant is desired from the scancode data, which in the case
  of
  NEC scancodes is a bit horrid since NEC scancodes are ambiguous. This
  actually means it's driver specific whether a filter mask of 0x
  filters out NEC32/NEC-X messages (scancode/encode driver probably will
  since it needs to pick a variant, but software fallback won't).
 
 How common is it that NEC codes are really ambiguous? Or that a wrong
 variant is selected for encoding? A quick look suggests that the
 length of the scancode will be good enough way to determine which
 variant is used for NEC, RC-5(X) and RC-6(A).

When I tried filtering for my TV remote it didn't work. It turned out to be 
because the extended nec scancode has the address bytes in the wrong order so 
that the bits are discontinuous compared to the raw data. The remote uses 
extended NEC but has zero in the lower byte of the address, which 
unfortunately goes in bits 23:16 of the scancode above the other byte of the 
address, so it looks as if it's using normal NEC (16bit scancodes). This is 
why I ended up making img-ir use the mask too in the decision.

It's ambiguous the other way too (which is probably a strong point against 
having actual protocol bits for each NEC variant, since they only differ in 
how the scancode is constructed). E.g. the Tivo keymap is 32-bit NEC, but has 
extended NEC scancodes where the bytes of the command are complements (i.e. 
the extended NEC command checksum passes). This makes it hard to filter on at 
the scancode level (the drivers will probably get it right for the hardware 
filters, but the software filter will likely get it wrong in those corner 
cases since it knows nothing of NEC).

There's multiple ways the NEC scancode formats could be improved 
(incompatibly!) to reduce the problems, but none are perfect.

E.g. one possibility is to scrap the NEC and extended NEC scancodes and just 
use 32-bit NEC scancodes format throughout:
0x[16-bit-address][16-bit-command]

which encodes scancodes for extended NEC like this:
0x[16-bit-address][~8-bit-command][8-bit-command]

and normal NEC like this:
0x[~8-bit-address][8-bit-address][~8-bit-command][8-bit-command]

Thanks
James

signature.asc
Description: This is a digitally signed message part.


Re: [PATCH v2 6/9] rc: ir-rc5-sz-decoder: Add ir encoding support

2014-03-16 Thread James Hogan
Hi Antti,

On Sunday 16 March 2014 10:34:31 Antti Seppälä wrote:
  +/**
  + * ir_rc5_sz_encode() - Encode a scancode as a stream of raw events
  + *
  + * @protocols: allowed protocols
  + * @scancode:  scancode filter describing scancode (helps distinguish
  between + * protocol subtypes when scancode is ambiguous)
  + * @events:array of raw ir events to write into
  + * @max:   maximum size of @events
  + *
  + * Returns:The number of events written.
  + * -ENOBUFS if there isn't enough space in the array to fit
  the + * encoding. In this case all @max events will have been
  written. + * -EINVAL if the scancode is ambiguous or invalid.
  + */
  +static int ir_rc5_sz_encode(u64 protocols,
  +   const struct rc_scancode_filter *scancode,
  +   struct ir_raw_event *events, unsigned int max)
  +{
  +   int ret;
  +   struct ir_raw_event *e = events;
  +
  +   /* all important bits of scancode should be set in mask */
  +   if (~scancode-mask  0x2fff)
 
 Do we want to be so restrictive here? In my opinion it's quite nice to
 be able to encode also the toggle bit if needed. Therefore a check
 against 0x3fff would be a better choice.
 
 I think the ability to encode toggle bit might also be nice to have
 for rc-5(x) also.
 

I don't believe the toggle bit is encoded in the scancode though, so I'm not 
sure it makes sense to treat it like that. I'm not an expert on RC-5 like 
protocols or the use of the toggle bit though.

  +   return -EINVAL;
  +   /* extra bits in mask should be zero in data */
  +   if (scancode-mask  scancode-data  ~0x2fff)
  +   return -EINVAL;
  +
  +   /* RC5-SZ scancode is raw enough for Manchester as it is */
  +   ret = ir_raw_gen_manchester(e, max, ir_rc5_sz_timings,
  RC5_SZ_NBITS, +   scancode-data 
  0x2fff);
 
 I'm not sure that the  0x2fff is necessary. It has the ill effect of
 eventually writing something else to hardware while still committing
 the filter as unmodified original value. This will result in
 difference between what sysfs states was written when read back and
 what was actually written.
 
 I think checks above are good enough to restrict the values and as
 little modification as possible of the data should be done after that.

I suspect it was the toggle bit I was thinking about, e.g.
echo 0x3fff  wakeup_filter
echo 0x2fff  wakeup_filter_mask

I had assumed shouldn't be able to affect the toggle bit (it's not set in 
mask).

Cheers
James

signature.asc
Description: This is a digitally signed message part.


Re: [PATCH v2 9/9] rc: nuvoton-cir: Add support for writing wakeup samples via sysfs filter callback

2014-03-16 Thread James Hogan
On Sunday 16 March 2014 10:39:39 Antti Seppälä wrote:
  +static int nvt_write_wakeup_codes(struct rc_dev *dev,
  + const u8 *wakeup_sample_buf, int count)
  +{
  +   int i = 0;
  +   u8 reg, reg_learn_mode;
  +   unsigned long flags;
  +   struct nvt_dev *nvt = dev-priv;
  +
  +   nvt_dbg_wake(writing wakeup samples);
  +
  +   reg = nvt_cir_wake_reg_read(nvt, CIR_WAKE_IRCON);
  +   reg_learn_mode = reg  ~CIR_WAKE_IRCON_MODE0;
  +   reg_learn_mode |= CIR_WAKE_IRCON_MODE1;
  +
  +   /* Lock the learn area to prevent racing with wake-isr */
  +   spin_lock_irqsave(nvt-nvt_lock, flags);
  +
  +   /* Enable fifo writes */
  +   nvt_cir_wake_reg_write(nvt, reg_learn_mode, CIR_WAKE_IRCON);
  +
  +   /* Clear cir wake rx fifo */
  +   nvt_clear_cir_wake_fifo(nvt);
  +
  +   if (count  WAKE_FIFO_LEN) {
  +   nvt_dbg_wake(HW FIFO too small for all wake samples);
  +   count = WAKE_FIFO_LEN;
  +   }
 
 Now that the encoders support partial encoding the above check against
 WAKE_FIFO_LEN never triggers and can be removed.

Yep, good point

Thanks
James

signature.asc
Description: This is a digitally signed message part.


Re: [PATCH v2 6/9] rc: ir-rc5-sz-decoder: Add ir encoding support

2014-03-16 Thread James Hogan
On Sunday 16 March 2014 14:14:58 Antti Seppälä wrote:
 Hi James.
 
 On 16 March 2014 13:50, James Hogan ja...@albanarts.com wrote:
  Hi Antti,
  
  On Sunday 16 March 2014 10:34:31 Antti Seppälä wrote:
   +
   +   /* all important bits of scancode should be set in mask */
   +   if (~scancode-mask  0x2fff)
  
  Do we want to be so restrictive here? In my opinion it's quite nice to
  be able to encode also the toggle bit if needed. Therefore a check
  against 0x3fff would be a better choice.
  
  I think the ability to encode toggle bit might also be nice to have
  for rc-5(x) also.
  
  I don't believe the toggle bit is encoded in the scancode though, so I'm
  not sure it makes sense to treat it like that. I'm not an expert on RC-5
  like protocols or the use of the toggle bit though.
 
 Well I'm not an expert either but at least streamzap tends to have the
 toggle bit enabled quite often when sending ir pulses.
 
 When decoding the toggle is always removed from the scancode but when
 encoding it would be useful to have the possibility to encode it in.
 This is because setting the toggle bit into wakeup makes it easier to
 wake the system with nuvoton hw as it is difficult to press the remote
 key short time enough (less than around 112ms) to generate a pulse
 without the toggle bit set.

Fair enough. So changing the minimum rc5-sz masks to 0x3fff sounds reasonable 
to allow toggle to be controlled.

Just to clarify though, so you mean that the remote uses toggle=1 first (and 
in repeat codes) unless you press it a second time (new keypress) within a 
short amount of time?
I.e. like this?
Press   message toggle=1
repeat toggle=1
repeat toggle=1
unpress
Press   message toggle=!last_toggle only if within X ms, 1 otherwise

Sounds like for RC-5/RC-5X toggle should probably be taken from 0x2000, 
0x0020 of scancode respectively (just above system in both cases).

Cheers
James

signature.asc
Description: This is a digitally signed message part.


Re: [PATCH v2 0/9] rc: Add IR encode based wakeup filtering

2014-03-16 Thread James Hogan
On Sunday 16 March 2014 10:22:02 Antti Seppälä wrote:
 On 15 March 2014 01:04, James Hogan ja...@albanarts.com wrote:
  A recent discussion about proposed interfaces for setting up the
  hardware wakeup filter lead to the conclusion that it could help to have
  the generic capability to encode and modulate scancodes into raw IR
  events so that drivers for hardware with a low level wake filter (on the
  level of pulse/space durations) can still easily implement the higher
  level scancode interface that is proposed.
  
  I posted an RFC patchset showing how this could work, and Antti Seppälä
  posted additional patches to support rc5-sz and nuvoton-cir. This
  patchset improves the original RFC patches and combines  updates
  Antti's patches.
  
  I'm happy these patches are a good start at tackling the problem, as
  long as Antti is happy with them and they work for him of course.
  
  Future work could include:
   - Encoders for more protocols.
   - Carrier signal events (no use unless a driver makes use of it).
  
  Patch 1 adds the new encode API.
  Patches 2-3 adds some modulation helpers.
  Patches 4-6 adds some raw encode implementations.
  Patch 7 adds some rc-core support for encode based wakeup filtering.
  Patch 8 adds debug loopback of encoded scancode when filter set.
  Patch 9 (untested) adds encode based wakeup filtering to nuvoton-cir.
 
 Hi James.
 
 This is looking very good. I've reviewed the series and have only
 minor comments to some of the patches which I'll post individually
 shortly.
 
 I've also tested the nuvoton with actual hardware with rc-5-sz and nec
 encoders and both generate wakeup samples correctly and can wake the
 system.

Thanks for reviewing and testing!

 While doing my tests I also noticed that there is a small bug in the
 wakeup_protocols handling where one can enable multiple protocols with
 the + -notation. E.g. echo +nec +rc-5 
 /sys/class/rc/rc0/wakeup_protocols shouldn't probably succeed.

Yeh I'm in two minds about this now. It's actually a little awkward since some 
of the protocols have multiple variants (i.e. rc-5 = RC5+RC5X), but an 
encoded message is only ever a single variant, so technically if you're going 
to draw the line for wakeup protocols it should probably be at one enabled 
variant, which isn't always convenient or necessary.

Note, ATM even disallowing +proto and -proto we would already have to 
guess which variant is desired from the scancode data, which in the case of 
NEC scancodes is a bit horrid since NEC scancodes are ambiguous. This actually 
means it's driver specific whether a filter mask of 0x filters out 
NEC32/NEC-X messages (scancode/encode driver probably will since it needs to 
pick a variant, but software fallback won't).

Ideally there'd now be a way to specify the protocol variants exactly as well 
as whole protocols groups through this sysfs interface (and probably NEC 
should have protocol bits for each variant too, which is tricky ATM since 
keymaps can use scancodes of multiple variants and it's hard to guarantee 
which variant was intended for each key mapping by reading it).

Adding proto_names entries for each variant is easy enough, though I'm not 
sure what you'd call the one for RC_BIT_RC5 (since rc-5 is taken to mean 
both RC5 and RC5X). We could then check that the enabled wakeup protocols fit 
entirely within one of the proto_names entry's proto mask if we think it's 
helpful (which would allow you to specify e.g. sony12, or sony (sony 
12,15,20), or sony -sony12 (sony 15,20), but not +sony +nec).

Cheers
James

signature.asc
Description: This is a digitally signed message part.


[PATCH v2 5/9] rc: ir-rc5-decoder: Add encode capability

2014-03-14 Thread James Hogan
Add the capability to encode RC-5 and RC-5X scancodes as raw events. The
protocol is chosen based on the specified protocol mask, and whether all
the required bits are set in the scancode mask, and none of the unused
bits are set in the scancode data. For example a scancode filter with
bit 16 set in both data and mask is unambiguously RC-5X.

The Manchester modulation helper is used, and for RC-5X it is used twice
with two sets of timings, the first with a short trailer space for the
space in the middle, and the second with no leader so that it can
continue the space.

Signed-off-by: James Hogan ja...@albanarts.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Antti Seppälä a.sepp...@gmail.com
Cc: David Härdeman da...@hardeman.nu
---
I've mostly reverse engineered RC-5X from the decoder, but it seems to
work in loopback. Here's some debug output:

RC-5X:
evbug: Event. Dev: input0, Type: 4, Code: 4, Value: 65793
evbug: Event. Dev: input0, Type: 0, Code: 0, Value: 0
 _   __   _   _   _   __  _   _   _   _   ___   _   _   _   __
| | |  | | | | | | | | |  | || | | | | | | | | |  |  | | | | | | | | |  | | 
 |
| |_|  |_| |_| |_| |_| |__| || |_| |_| |_| |_| |__|  |_| |_| |_| |_| |__| 
|__|
  1  1  31  1  1
8
 8 8  7 8 8 8 8 8 8 8 8  7 85 8 8 8 8 8 8 8 8 8  7  7 8 8 8 8 8 8 8 8  7 8  
8
 8 8  7 8 8 8 8 8 8 8 8  7 85 8 8 8 8 8 8 8 8 8  7  7 8 8 8 8 8 8 8 8  7 8  
8
 9 9  8 9 9 9 9 9 9 9 9  8 96 9 9 9 9 9 9 9 9 9  8  8 9 9 9 9 9 9 9 9  8 9  
9
   1  0   0   0   0   0  1  X 0   0   0   0   0  1  0   0   0   0   0  1
E rc-5

RC-5:
evbug: Event. Dev: input0, Type: 4, Code: 4, Value: 257
evbug: Event. Dev: input0, Type: 0, Code: 0, Value: 0
 _   __   _   _   _   ___   _   _   _   __
| | |  | | | | | | | | |  |  | | | | | | | | |  | |  |
| |_|  |_| |_| |_| |_| |__|  |_| |_| |_| |_| |__| |__|
  1  1  1  18
 8 8  7 8 8 8 8 8 8 8 8  7  7 8 8 8 8 8 8 8 8  7 8  8
 8 8  7 8 8 8 8 8 8 8 8  7  7 8 8 8 8 8 8 8 8  7 8  8
 9 9  8 9 9 9 9 9 9 9 9  8  8 9 9 9 9 9 9 9 9  8 9  9
   1  0   0   0   0   0  1  0   0   0   0   0  1E rc-5
---
 drivers/media/rc/ir-rc5-decoder.c | 103 ++
 1 file changed, 103 insertions(+)

diff --git a/drivers/media/rc/ir-rc5-decoder.c 
b/drivers/media/rc/ir-rc5-decoder.c
index 4295d9b..2eed2fe 100644
--- a/drivers/media/rc/ir-rc5-decoder.c
+++ b/drivers/media/rc/ir-rc5-decoder.c
@@ -171,9 +171,112 @@ out:
return -EINVAL;
 }
 
+static struct ir_raw_timings_manchester ir_rc5_timings = {
+   .leader = 1,
+   .pulse_space_start  = 0,
+   .clock  = RC5_UNIT,
+   .trailer_space  = RC5_UNIT * 10,
+};
+
+static struct ir_raw_timings_manchester ir_rc5x_timings[2] = {
+   {
+   .leader = 1,
+   .pulse_space_start  = 0,
+   .clock  = RC5_UNIT,
+   .trailer_space  = RC5X_SPACE,
+   },
+   {
+   .clock  = RC5_UNIT,
+   .trailer_space  = RC5_UNIT * 10,
+   },
+};
+
+static int ir_rc5_validate_filter(const struct rc_scancode_filter *scancode,
+ unsigned int important_bits)
+{
+   /* all important bits of scancode should be set in mask */
+   if (~scancode-mask  important_bits)
+   return -EINVAL;
+   /* extra bits in mask should be zero in data */
+   if (scancode-mask  scancode-data  ~important_bits)
+   return -EINVAL;
+   return 0;
+}
+
+/**
+ * ir_rc5_encode() - Encode a scancode as a stream of raw events
+ *
+ * @protocols: allowed protocols
+ * @scancode:  scancode filter describing scancode (helps distinguish between
+ * protocol subtypes when scancode is ambiguous)
+ * @events:array of raw ir events to write into
+ * @max:   maximum size of @events
+ *
+ * Returns:The number of events written.
+ * -ENOBUFS if there isn't enough space in the array to fit the
+ * encoding. In this case all @max events will have been written.
+ * -EINVAL if the scancode is ambiguous or invalid.
+ */
+static int ir_rc5_encode(u64 protocols,
+const struct rc_scancode_filter *scancode,
+struct ir_raw_event *events, unsigned int max)
+{
+   int ret;
+   struct ir_raw_event *e = events;
+   unsigned int data, xdata, command, commandx, system;
+
+   /* Detect protocol and convert scancode to raw data */
+   if (protocols  RC_BIT_RC5 
+   !ir_rc5_validate_filter(scancode, 0x1f7f)) {
+   /* decode scancode */
+   command  = (scancode-data  0x003f)  0;
+   commandx

[PATCH v2 0/9] rc: Add IR encode based wakeup filtering

2014-03-14 Thread James Hogan
A recent discussion about proposed interfaces for setting up the
hardware wakeup filter lead to the conclusion that it could help to have
the generic capability to encode and modulate scancodes into raw IR
events so that drivers for hardware with a low level wake filter (on the
level of pulse/space durations) can still easily implement the higher
level scancode interface that is proposed.

I posted an RFC patchset showing how this could work, and Antti Seppälä
posted additional patches to support rc5-sz and nuvoton-cir. This
patchset improves the original RFC patches and combines  updates
Antti's patches.

I'm happy these patches are a good start at tackling the problem, as
long as Antti is happy with them and they work for him of course.

Future work could include:
 - Encoders for more protocols.
 - Carrier signal events (no use unless a driver makes use of it).

Patch 1 adds the new encode API.
Patches 2-3 adds some modulation helpers.
Patches 4-6 adds some raw encode implementations.
Patch 7 adds some rc-core support for encode based wakeup filtering.
Patch 8 adds debug loopback of encoded scancode when filter set.
Patch 9 (untested) adds encode based wakeup filtering to nuvoton-cir.

Changes in v2:

Patchset:
 - Alter encode API to return -ENOBUFS when there isn't enough buffer
   space. When this occurs all buffer contents must have been written
   with the partial encoding of the scancode. This is to allow drivers
   such as nuvoton-cir to provide a shorter buffer and still get a
   useful partial encoding for the wakeup pattern.
 - Added RC-5  RC-5X encoder.
 - Add encode_wakeup support which keeps allowed wakeup protocols in
   sync with registered encoders.

Pulse-distance modulation helper:
 - Update ir_raw_gen_pd() with a kerneldoc comment and individual buffer
   full checks rather than a single one at the beginning, in order to
   support -ENOBUFS properly.
 - Update ir_raw_gen_pulse_space() to check the number of free slots and
   fill as many as possible before returning -ENOBUFS.
 - Fix brace placement for timings struct.

Manchester encoding helper:
 - Add kerneldoc comment.
 - Add individual buffer full checks, in order to support -ENOBUFS
   properly.
 - Make i unsigned to theoretically support all 32bits of data.
 - Increment *ev at end so caller can calculate correct number of
   events (during the loop *ev points to the last written event to allow
   it to be extended in length).
 - Make start/leader pulse optional, continuing from (*ev)[-1] if
   disabled. This helps support rc-5x which has a space in the middle of
   the bits.

rc5-sz encoder:
 - Turn ir_rc5_sz_encode() comment into kerneldoc and update to reflect
   new API.
 - Be more flexible around accepted scancode masks, as long as all the
   important bits are set (0x2fff) and none of the unimportant bits are
   set in the data. Also mask off the unimportant bits before passing to
   ir_raw_gen_manchester().
 - Explicitly enable leader bit in Manchester modulation timings.

rc-loopback:
 - Move img-ir-raw test code to rc-loopback.
 - Set encode_wakeup so that the set of allowed wakeup protocols matches
   the set of raw IR encoders.

nuvoton-cir:
 - Change reference to rc_dev::enabled_protocols to
   enabled_protocols[type] since it has been converted to an array.
 - Fix IR encoding buffer loop condition to be i  ret rather than i =
   ret. The return value of ir_raw_encode_scancode is the number of
   events rather than the last event.
 - Set encode_wakeup so that the set of allowed wakeup protocols matches
   the set of raw IR encoders.

Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Antti Seppälä a.sepp...@gmail.com
Cc: David Härdeman da...@hardeman.nu
Cc: Jarod Wilson ja...@redhat.com
Cc: Wei Yongjun yongjun_...@trendmicro.com.cn
Cc: Hans Verkuil hans.verk...@cisco.com

Antti Seppälä (3):
  rc: ir-raw: Add Manchester encoder (phase encoder) helper
  rc: ir-rc5-sz-decoder: Add ir encoding support
  rc: nuvoton-cir: Add support for writing wakeup samples via sysfs
filter callback

James Hogan (6):
  rc: ir-raw: Add scancode encoder callback
  rc: ir-raw: Add pulse-distance modulation helper
  rc: ir-nec-decoder: Add encode capability
  rc: ir-rc5-decoder: Add encode capability
  rc: rc-core: Add support for encode_wakeup drivers
  rc: rc-loopback: Add loopback of filter scancodes

 drivers/media/rc/ir-nec-decoder.c|  93 +
 drivers/media/rc/ir-raw.c| 191 +++
 drivers/media/rc/ir-rc5-decoder.c| 103 +++
 drivers/media/rc/ir-rc5-sz-decoder.c |  45 +
 drivers/media/rc/nuvoton-cir.c   | 123 ++
 drivers/media/rc/nuvoton-cir.h   |   1 +
 drivers/media/rc/rc-core-priv.h  |  85 
 drivers/media/rc/rc-loopback.c   |  39 +++
 drivers/media/rc/rc-main.c   |  11 +-
 include/media/rc-core.h  |   7 ++
 10 files changed, 695 insertions(+), 3 deletions(-)

-- 
1.8.3.2

[PATCH v2 1/9] rc: ir-raw: Add scancode encoder callback

2014-03-14 Thread James Hogan
Add a callback to raw ir handlers for encoding and modulating a scancode
to a set of raw events. This could be used for transmit, or for
converting a wakeup scancode filter to a form that is more suitable for
raw hardware wake up filters.

Signed-off-by: James Hogan ja...@albanarts.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Antti Seppälä a.sepp...@gmail.com
Cc: David Härdeman da...@hardeman.nu
---
Changes in v2:
 - Alter encode API to return -ENOBUFS when there isn't enough buffer
   space. When this occurs all buffer contents must have been written
   with the partial encoding of the scancode. This is to allow drivers
   such as nuvoton-cir to provide a shorter buffer and still get a
   useful partial encoding for the wakeup pattern.
---
 drivers/media/rc/ir-raw.c   | 38 ++
 drivers/media/rc/rc-core-priv.h |  2 ++
 include/media/rc-core.h |  3 +++
 3 files changed, 43 insertions(+)

diff --git a/drivers/media/rc/ir-raw.c b/drivers/media/rc/ir-raw.c
index 763c9d1..01adc10 100644
--- a/drivers/media/rc/ir-raw.c
+++ b/drivers/media/rc/ir-raw.c
@@ -240,6 +240,44 @@ ir_raw_get_allowed_protocols(void)
return protocols;
 }
 
+/**
+ * ir_raw_encode_scancode() - Encode a scancode as raw events
+ *
+ * @protocols: permitted protocols
+ * @scancode:  scancode filter describing a single scancode
+ * @events:array of raw events to write into
+ * @max:   max number of raw events
+ *
+ * Attempts to encode the scancode as raw events.
+ *
+ * Returns:The number of events written.
+ * -ENOBUFS if there isn't enough space in the array to fit the
+ * encoding. In this case all @max events will have been written.
+ * -EINVAL if the scancode is ambiguous or invalid, or if no
+ * compatible encoder was found.
+ */
+int ir_raw_encode_scancode(u64 protocols,
+  const struct rc_scancode_filter *scancode,
+  struct ir_raw_event *events, unsigned int max)
+{
+   struct ir_raw_handler *handler;
+   int ret = -EINVAL;
+
+   mutex_lock(ir_raw_handler_lock);
+   list_for_each_entry(handler, ir_raw_handler_list, list) {
+   if (handler-protocols  protocols  handler-encode) {
+   ret = handler-encode(protocols, scancode, events, max);
+   if (ret = 0 || ret == -ENOBUFS)
+   break;
+   }
+   }
+   mutex_unlock(ir_raw_handler_lock);
+
+   return ret;
+}
+EXPORT_SYMBOL(ir_raw_encode_scancode);
+
+
 /*
  * Used to (un)register raw event clients
  */
diff --git a/drivers/media/rc/rc-core-priv.h b/drivers/media/rc/rc-core-priv.h
index da536c9..8afb971 100644
--- a/drivers/media/rc/rc-core-priv.h
+++ b/drivers/media/rc/rc-core-priv.h
@@ -25,6 +25,8 @@ struct ir_raw_handler {
 
u64 protocols; /* which are handled by this handler */
int (*decode)(struct rc_dev *dev, struct ir_raw_event event);
+   int (*encode)(u64 protocols, const struct rc_scancode_filter *scancode,
+ struct ir_raw_event *events, unsigned int max);
 
/* These two should only be used by the lirc decoder */
int (*raw_register)(struct rc_dev *dev);
diff --git a/include/media/rc-core.h b/include/media/rc-core.h
index 0b9f890..8c64f9e 100644
--- a/include/media/rc-core.h
+++ b/include/media/rc-core.h
@@ -275,6 +275,9 @@ int ir_raw_event_store_edge(struct rc_dev *dev, enum 
raw_event_type type);
 int ir_raw_event_store_with_filter(struct rc_dev *dev,
struct ir_raw_event *ev);
 void ir_raw_event_set_idle(struct rc_dev *dev, bool idle);
+int ir_raw_encode_scancode(u64 protocols,
+  const struct rc_scancode_filter *scancode,
+  struct ir_raw_event *events, unsigned int max);
 
 static inline void ir_raw_event_reset(struct rc_dev *dev)
 {
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 3/9] rc: ir-raw: Add Manchester encoder (phase encoder) helper

2014-03-14 Thread James Hogan
From: Antti Seppälä a.sepp...@gmail.com

Adding a simple Manchester encoder to rc-core.
Manchester coding is used by at least RC-5 protocol and its variants.

Signed-off-by: Antti Seppälä a.sepp...@gmail.com
Signed-off-by: James Hogan ja...@albanarts.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: David Härdeman da...@hardeman.nu
---
Changes in v2 (James Hogan):
 - Alter encode API to return -ENOBUFS when there isn't enough buffer
   space. When this occurs all buffer contents must have been written
   with the partial encoding of the scancode. This is to allow drivers
   such as nuvoton-cir to provide a shorter buffer and still get a
   useful partial encoding for the wakeup pattern.
 - Add kerneldoc comment.
 - Add individual buffer full checks, in order to support -ENOBUFS
   properly.
 - Make i unsigned to theoretically support all 32bits of data.
 - Increment *ev at end so caller can calculate correct number of
   events (during the loop *ev points to the last written event to allow
   it to be extended in length).
 - Make start/leader pulse optional, continuing from (*ev)[-1] if
   disabled. This helps support rc-5x which has a space in the middle of
   the bits.
---
 drivers/media/rc/ir-raw.c   | 82 +
 drivers/media/rc/rc-core-priv.h | 19 ++
 2 files changed, 101 insertions(+)

diff --git a/drivers/media/rc/ir-raw.c b/drivers/media/rc/ir-raw.c
index f8fe10e..4310e82 100644
--- a/drivers/media/rc/ir-raw.c
+++ b/drivers/media/rc/ir-raw.c
@@ -241,6 +241,88 @@ ir_raw_get_allowed_protocols(void)
 }
 
 /**
+ * ir_raw_gen_manchester() - Encode data with Manchester (bi-phase) modulation.
+ * @ev:Pointer to pointer to next free event. *@ev is 
incremented for
+ * each raw event filled.
+ * @max:   Maximum number of raw events to fill.
+ * @timings:   Manchester modulation timings.
+ * @n: Number of bits of data.
+ * @data:  Data bits to encode.
+ *
+ * Encodes the @n least significant bits of @data using Manchester (bi-phase)
+ * modulation with the timing characteristics described by @timings, writing up
+ * to @max raw IR events using the *@ev pointer.
+ *
+ * Returns:0 on success.
+ * -ENOBUFS if there isn't enough space in the array to fit the
+ * full encoded data. In this case all @max events will have been
+ * written.
+ */
+int ir_raw_gen_manchester(struct ir_raw_event **ev, unsigned int max,
+ const struct ir_raw_timings_manchester *timings,
+ unsigned int n, unsigned int data)
+{
+   bool need_pulse;
+   unsigned int i;
+   int ret = -ENOBUFS;
+   i = 1  (n - 1);
+
+   if (timings-leader) {
+   if (!max--)
+   return ret;
+   if (timings-pulse_space_start) {
+   init_ir_raw_event_duration((*ev)++, 1, timings-clock);
+
+   if (!max--)
+   return ret;
+   init_ir_raw_event_duration((*ev), 0, timings-clock);
+   } else {
+   init_ir_raw_event_duration((*ev), 1, timings-clock);
+   }
+   i = 1;
+   } else {
+   /* continue existing signal */
+   --(*ev);
+   }
+   /* from here on *ev will point to the last event rather than the next */
+
+   while (i  0) {
+   need_pulse = !(data  i);
+   if (need_pulse == !!(*ev)-pulse) {
+   (*ev)-duration += timings-clock;
+   } else {
+   if (!max--)
+   goto nobufs;
+   init_ir_raw_event_duration(++(*ev), need_pulse,
+  timings-clock);
+   }
+
+   if (!max--)
+   goto nobufs;
+   init_ir_raw_event_duration(++(*ev), !need_pulse,
+  timings-clock);
+   i = 1;
+   }
+
+   if (timings-trailer_space) {
+   if (!(*ev)-pulse)
+   (*ev)-duration += timings-trailer_space;
+   else if (!max--)
+   goto nobufs;
+   else
+   init_ir_raw_event_duration(++(*ev), 0,
+  timings-trailer_space);
+   }
+
+   ret = 0;
+nobufs:
+   /* point to the next event rather than last event before returning */
+   ++(*ev);
+   return ret;
+}
+EXPORT_SYMBOL(ir_raw_gen_manchester);
+
+/**
  * ir_raw_gen_pd() - Encode data to raw events with pulse-distance modulation.
  * @ev:Pointer to pointer to next free event. *@ev is 
incremented for
  * each raw event filled.
diff --git a/drivers/media/rc/rc-core-priv.h b/drivers/media/rc/rc-core-priv.h
index b55ae24..c45b797 100644
--- a/drivers/media/rc

[PATCH v2 4/9] rc: ir-nec-decoder: Add encode capability

2014-03-14 Thread James Hogan
Add the capability to encode NEC scancodes as raw events. The
scancode_to_raw is pretty much taken from the img-ir NEC filter()
callback, and modulation uses the pulse distance helper added in a
previous commit.

Signed-off-by: James Hogan ja...@albanarts.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Antti Seppälä a.sepp...@gmail.com
Cc: David Härdeman da...@hardeman.nu
---
Changes in v2:
 - Update kerneldoc return values to reflect new API with -ENOBUFS
   return value when buffer is full and only a partial message was
   encoded.
---
 drivers/media/rc/ir-nec-decoder.c | 93 +++
 1 file changed, 93 insertions(+)

diff --git a/drivers/media/rc/ir-nec-decoder.c 
b/drivers/media/rc/ir-nec-decoder.c
index 9de1791..813fa6b 100644
--- a/drivers/media/rc/ir-nec-decoder.c
+++ b/drivers/media/rc/ir-nec-decoder.c
@@ -203,9 +203,102 @@ static int ir_nec_decode(struct rc_dev *dev, struct 
ir_raw_event ev)
return -EINVAL;
 }
 
+/**
+ * ir_nec_scancode_to_raw() - encode an NEC scancode ready for modulation.
+ * @in:scancode filter describing a single NEC scancode.
+ * @raw:   raw data to be modulated.
+ */
+static int ir_nec_scancode_to_raw(const struct rc_scancode_filter *in,
+ u32 *raw)
+{
+   unsigned int addr, addr_inv, data, data_inv;
+
+   data = in-data  0xff;
+
+   if ((in-data | in-mask)  0xff00) {
+   /* 32-bit NEC (used by Apple and TiVo remotes) */
+   /* scan encoding: aaAAddDD */
+   if (in-mask != 0x)
+   return -EINVAL;
+   addr_inv   = (in-data  24)  0xff;
+   addr   = (in-data  16)  0xff;
+   data_inv   = (in-data   8)  0xff;
+   } else if ((in-data | in-mask)  0x00ff) {
+   /* Extended NEC */
+   /* scan encoding AAaaDD */
+   if (in-mask != 0x00ff)
+   return -EINVAL;
+   addr   = (in-data  16)  0xff;
+   addr_inv   = (in-data   8)  0xff;
+   data_inv   = data ^ 0xff;
+   } else {
+   /* Normal NEC */
+   /* scan encoding: AADD */
+   if (in-mask != 0x)
+   return -EINVAL;
+   addr   = (in-data   8)  0xff;
+   addr_inv   = addr ^ 0xff;
+   data_inv   = data ^ 0xff;
+   }
+
+   /* raw encoding: ddDDaaAA */
+   *raw = data_inv  24 |
+  data  16 |
+  addr_inv   8 |
+  addr;
+   return 0;
+}
+
+static struct ir_raw_timings_pd ir_nec_timings = {
+   .header_pulse   = NEC_HEADER_PULSE,
+   .header_space   = NEC_HEADER_SPACE,
+   .bit_pulse  = NEC_BIT_PULSE,
+   .bit_space[0]   = NEC_BIT_0_SPACE,
+   .bit_space[1]   = NEC_BIT_1_SPACE,
+   .trailer_pulse  = NEC_TRAILER_PULSE,
+   .trailer_space  = NEC_TRAILER_SPACE,
+   .msb_first  = 0,
+};
+
+/**
+ * ir_nec_encode() - Encode a scancode as a stream of raw events
+ *
+ * @protocols: allowed protocols
+ * @scancode:  scancode filter describing scancode (helps distinguish between
+ * protocol subtypes when scancode is ambiguous)
+ * @events:array of raw ir events to write into
+ * @max:   maximum size of @events
+ *
+ * Returns:The number of events written.
+ * -ENOBUFS if there isn't enough space in the array to fit the
+ * encoding. In this case all @max events will have been written.
+ * -EINVAL if the scancode is ambiguous or invalid.
+ */
+static int ir_nec_encode(u64 protocols,
+const struct rc_scancode_filter *scancode,
+struct ir_raw_event *events, unsigned int max)
+{
+   struct ir_raw_event *e = events;
+   int ret;
+   u32 raw;
+
+   /* Convert a NEC scancode to raw NEC data */
+   ret = ir_nec_scancode_to_raw(scancode, raw);
+   if (ret  0)
+   return ret;
+
+   /* Modulate the raw data using a pulse distance modulation */
+   ret = ir_raw_gen_pd(e, max, ir_nec_timings, NEC_NBITS, raw);
+   if (ret  0)
+   return ret;
+
+   return e - events;
+}
+
 static struct ir_raw_handler nec_handler = {
.protocols  = RC_BIT_NEC,
.decode = ir_nec_decode,
+   .encode = ir_nec_encode,
 };
 
 static int __init ir_nec_decode_init(void)
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 6/9] rc: ir-rc5-sz-decoder: Add ir encoding support

2014-03-14 Thread James Hogan
From: Antti Seppälä a.sepp...@gmail.com

The encoding in rc5-sz first inserts a pulse and then simply utilizes the
generic Manchester encoder available in rc-core.

Signed-off-by: Antti Seppälä a.sepp...@gmail.com
Signed-off-by: James Hogan ja...@albanarts.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: David Härdeman da...@hardeman.nu
---
Changes in v2 (James Hogan):
 - Turn ir_rc5_sz_encode() comment into kerneldoc and update to reflect
   new API, with the -ENOBUFS return value for when the buffer is full
   and only a partial message was encoded.
 - Be more flexible around accepted scancode masks, as long as all the
   important bits are set (0x2fff) and none of the unimportant bits are
   set in the data. Also mask off the unimportant bits before passing to
   ir_raw_gen_manchester().
 - Explicitly enable leader bit in Manchester modulation timings.
---
 drivers/media/rc/ir-rc5-sz-decoder.c | 45 
 1 file changed, 45 insertions(+)

diff --git a/drivers/media/rc/ir-rc5-sz-decoder.c 
b/drivers/media/rc/ir-rc5-sz-decoder.c
index dc18b74..a342a4f 100644
--- a/drivers/media/rc/ir-rc5-sz-decoder.c
+++ b/drivers/media/rc/ir-rc5-sz-decoder.c
@@ -127,9 +127,54 @@ out:
return -EINVAL;
 }
 
+static struct ir_raw_timings_manchester ir_rc5_sz_timings = {
+   .leader = 1,
+   .pulse_space_start  = 0,
+   .clock  = RC5_UNIT,
+   .trailer_space  = RC5_UNIT * 10,
+};
+
+/**
+ * ir_rc5_sz_encode() - Encode a scancode as a stream of raw events
+ *
+ * @protocols: allowed protocols
+ * @scancode:  scancode filter describing scancode (helps distinguish between
+ * protocol subtypes when scancode is ambiguous)
+ * @events:array of raw ir events to write into
+ * @max:   maximum size of @events
+ *
+ * Returns:The number of events written.
+ * -ENOBUFS if there isn't enough space in the array to fit the
+ * encoding. In this case all @max events will have been written.
+ * -EINVAL if the scancode is ambiguous or invalid.
+ */
+static int ir_rc5_sz_encode(u64 protocols,
+   const struct rc_scancode_filter *scancode,
+   struct ir_raw_event *events, unsigned int max)
+{
+   int ret;
+   struct ir_raw_event *e = events;
+
+   /* all important bits of scancode should be set in mask */
+   if (~scancode-mask  0x2fff)
+   return -EINVAL;
+   /* extra bits in mask should be zero in data */
+   if (scancode-mask  scancode-data  ~0x2fff)
+   return -EINVAL;
+
+   /* RC5-SZ scancode is raw enough for Manchester as it is */
+   ret = ir_raw_gen_manchester(e, max, ir_rc5_sz_timings, RC5_SZ_NBITS,
+   scancode-data  0x2fff);
+   if (ret  0)
+   return ret;
+
+   return e - events;
+}
+
 static struct ir_raw_handler rc5_sz_handler = {
.protocols  = RC_BIT_RC5_SZ,
.decode = ir_rc5_sz_decode,
+   .encode = ir_rc5_sz_encode,
 };
 
 static int __init ir_rc5_sz_decode_init(void)
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 7/9] rc: rc-core: Add support for encode_wakeup drivers

2014-03-14 Thread James Hogan
Add support in rc-core for drivers which implement the wakeup scancode
filter by encoding the scancode using the raw IR encoders. This is by
way of rc_dev::encode_wakeup which should be set to true to make the
allowed wakeup protocols the same as the set of raw IR encoders.

As well as updating the sysfs interface to know which wakeup protocols
are allowed for encode_wakeup drivers, also ensure that the IR
decoders/encoders are loaded when an encode_wakeup driver is registered.

Signed-off-by: James Hogan ja...@albanarts.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Antti Seppälä a.sepp...@gmail.com
Cc: David Härdeman da...@hardeman.nu
---
Changes in v2:
 - New patch
---
 drivers/media/rc/ir-raw.c   | 15 +++
 drivers/media/rc/rc-core-priv.h |  1 +
 drivers/media/rc/rc-main.c  | 11 ---
 include/media/rc-core.h |  3 +++
 4 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/media/rc/ir-raw.c b/drivers/media/rc/ir-raw.c
index 4310e82..d8ad81c 100644
--- a/drivers/media/rc/ir-raw.c
+++ b/drivers/media/rc/ir-raw.c
@@ -30,6 +30,7 @@ static LIST_HEAD(ir_raw_client_list);
 static DEFINE_MUTEX(ir_raw_handler_lock);
 static LIST_HEAD(ir_raw_handler_list);
 static u64 available_protocols;
+static u64 encode_protocols;
 
 static int ir_raw_event_thread(void *data)
 {
@@ -240,6 +241,16 @@ ir_raw_get_allowed_protocols(void)
return protocols;
 }
 
+/* used internally by the sysfs interface */
+u64 ir_raw_get_encode_protocols(void)
+{
+   u64 protocols;
+   mutex_lock(ir_raw_handler_lock);
+   protocols = encode_protocols;
+   mutex_unlock(ir_raw_handler_lock);
+   return protocols;
+}
+
 /**
  * ir_raw_gen_manchester() - Encode data with Manchester (bi-phase) modulation.
  * @ev:Pointer to pointer to next free event. *@ev is 
incremented for
@@ -498,6 +509,8 @@ int ir_raw_handler_register(struct ir_raw_handler 
*ir_raw_handler)
list_for_each_entry(raw, ir_raw_client_list, list)
ir_raw_handler-raw_register(raw-dev);
available_protocols |= ir_raw_handler-protocols;
+   if (ir_raw_handler-encode)
+   encode_protocols |= ir_raw_handler-protocols;
mutex_unlock(ir_raw_handler_lock);
 
return 0;
@@ -514,6 +527,8 @@ void ir_raw_handler_unregister(struct ir_raw_handler 
*ir_raw_handler)
list_for_each_entry(raw, ir_raw_client_list, list)
ir_raw_handler-raw_unregister(raw-dev);
available_protocols = ~ir_raw_handler-protocols;
+   if (ir_raw_handler-encode)
+   encode_protocols = ~ir_raw_handler-protocols;
mutex_unlock(ir_raw_handler_lock);
 }
 EXPORT_SYMBOL(ir_raw_handler_unregister);
diff --git a/drivers/media/rc/rc-core-priv.h b/drivers/media/rc/rc-core-priv.h
index c45b797..767ef69 100644
--- a/drivers/media/rc/rc-core-priv.h
+++ b/drivers/media/rc/rc-core-priv.h
@@ -239,6 +239,7 @@ int ir_raw_gen_pd(struct ir_raw_event **ev, unsigned int 
max,
  * Routines from rc-raw.c to be used internally and by decoders
  */
 u64 ir_raw_get_allowed_protocols(void);
+u64 ir_raw_get_encode_protocols(void);
 int ir_raw_event_register(struct rc_dev *dev);
 void ir_raw_event_unregister(struct rc_dev *dev);
 int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler);
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 99697aa..712a2d7 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -857,8 +857,10 @@ static ssize_t show_protocols(struct device *device,
mutex_lock(dev-lock);
 
enabled = dev-enabled_protocols[fattr-type];
-   if (dev-driver_type == RC_DRIVER_SCANCODE ||
-   fattr-type == RC_FILTER_WAKEUP)
+   if (dev-encode_wakeup  fattr-type == RC_FILTER_WAKEUP)
+   allowed = ir_raw_get_encode_protocols();
+   else if (dev-driver_type == RC_DRIVER_SCANCODE ||
+fattr-type == RC_FILTER_WAKEUP)
allowed = dev-allowed_protocols[fattr-type];
else if (dev-raw)
allowed = ir_raw_get_allowed_protocols();
@@ -1350,13 +1352,16 @@ int rc_register_device(struct rc_dev *dev)
path ? path : N/A);
kfree(path);
 
-   if (dev-driver_type == RC_DRIVER_IR_RAW) {
+   if (dev-driver_type == RC_DRIVER_IR_RAW || dev-encode_wakeup) {
/* Load raw decoders, if they aren't already */
if (!raw_init) {
IR_dprintk(1, Loading raw decoders\n);
ir_raw_init();
raw_init = true;
}
+   }
+
+   if (dev-driver_type == RC_DRIVER_IR_RAW) {
rc = ir_raw_event_register(dev);
if (rc  0)
goto out_input;
diff --git a/include/media/rc-core.h b/include/media/rc-core.h
index 8c64f9e..2d81d6c 100644
--- a/include/media/rc-core.h
+++ b/include/media/rc-core.h
@@ -73,6 +73,8

[PATCH v2 8/9] rc: rc-loopback: Add loopback of filter scancodes

2014-03-14 Thread James Hogan
Add the s_filter callback to the rc-loopback driver, which instead of
setting the filter just feeds the scancode back through the input device
so that it can be verified.

Signed-off-by: James Hogan ja...@albanarts.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Antti Seppälä a.sepp...@gmail.com
---
Changes in v2:
 - Move img-ir-raw test code to rc-loopback.
 - Handle new encode API, specifically -ENOBUFS when the buffer isn't
   long enough.
 - Set encode_wakeup so that the set of allowed wakeup protocols matches
   the set of raw IR encoders.
---
 drivers/media/rc/rc-loopback.c | 39 +++
 1 file changed, 39 insertions(+)

diff --git a/drivers/media/rc/rc-loopback.c b/drivers/media/rc/rc-loopback.c
index 0a88e0c..aefd335 100644
--- a/drivers/media/rc/rc-loopback.c
+++ b/drivers/media/rc/rc-loopback.c
@@ -26,6 +26,7 @@
 #include linux/device.h
 #include linux/module.h
 #include linux/sched.h
+#include linux/slab.h
 #include media/rc-core.h
 
 #define DRIVER_NAMErc-loopback
@@ -176,6 +177,42 @@ static int loop_set_carrier_report(struct rc_dev *dev, int 
enable)
return 0;
 }
 
+static int loop_set_filter(struct rc_dev *dev, enum rc_filter_type type,
+  struct rc_scancode_filter *sc_filter)
+{
+   static const unsigned int max = 512;
+   struct ir_raw_event *raw;
+   int ret;
+   int i;
+
+   /* fine to disable filter */
+   if (!sc_filter-mask)
+   return 0;
+
+   /* encode the specified filter and loop it back */
+   raw = kmalloc(max * sizeof(*raw), GFP_KERNEL);
+   ret = ir_raw_encode_scancode(dev-enabled_protocols[type], sc_filter,
+raw, max);
+   /* still loop back the partial raw IR even if it's incomplete */
+   if (ret == -ENOBUFS)
+   ret = max;
+   if (ret = 0) {
+   /* do the loopback */
+   for (i = 0; i  ret; ++i)
+   ir_raw_event_store(dev, raw[i]);
+   ir_raw_event_handle(dev);
+
+   ret = 0;
+   } else if (type == RC_FILTER_NORMAL) {
+   /* accept any normal filter */
+   ret = 0;
+   }
+
+   kfree(raw);
+
+   return ret;
+}
+
 static int __init loop_init(void)
 {
struct rc_dev *rc;
@@ -195,6 +232,7 @@ static int __init loop_init(void)
rc-map_name= RC_MAP_EMPTY;
rc-priv= loopdev;
rc-driver_type = RC_DRIVER_IR_RAW;
+   rc-encode_wakeup   = true;
rc_set_allowed_protocols(rc, RC_BIT_ALL);
rc-timeout = 100 * 1000 * 1000; /* 100 ms */
rc-min_timeout = 1;
@@ -209,6 +247,7 @@ static int __init loop_init(void)
rc-s_idle  = loop_set_idle;
rc-s_learning_mode = loop_set_learning_mode;
rc-s_carrier_report= loop_set_carrier_report;
+   rc-s_filter= loop_set_filter;
 
loopdev.txmask  = RXMASK_REGULAR;
loopdev.txcarrier   = 36000;
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/9] rc: ir-raw: Add pulse-distance modulation helper

2014-03-14 Thread James Hogan
Add IR encoding helper for pulse-distance modulation as used by the NEC
protocol.

Signed-off-by: James Hogan ja...@albanarts.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Antti Seppälä a.sepp...@gmail.com
Cc: David Härdeman da...@hardeman.nu
---
Changes in v2:
 - Alter encode API to return -ENOBUFS when there isn't enough buffer
   space. When this occurs all buffer contents must have been written
   with the partial encoding of the scancode. This is to allow drivers
   such as nuvoton-cir to provide a shorter buffer and still get a
   useful partial encoding for the wakeup pattern.
 - Update ir_raw_gen_pd() with a kerneldoc comment and individual buffer
   full checks rather than a single one at the beginning, in order to
   support -ENOBUFS properly.
 - Update ir_raw_gen_pulse_space() to check the number of free slots and
   fill as many as possible before returning -ENOBUFS.
 - Fix brace placement for timings struct.
---
 drivers/media/rc/ir-raw.c   | 56 
 drivers/media/rc/rc-core-priv.h | 63 +
 2 files changed, 119 insertions(+)

diff --git a/drivers/media/rc/ir-raw.c b/drivers/media/rc/ir-raw.c
index 01adc10..f8fe10e 100644
--- a/drivers/media/rc/ir-raw.c
+++ b/drivers/media/rc/ir-raw.c
@@ -241,6 +241,62 @@ ir_raw_get_allowed_protocols(void)
 }
 
 /**
+ * ir_raw_gen_pd() - Encode data to raw events with pulse-distance modulation.
+ * @ev:Pointer to pointer to next free event. *@ev is 
incremented for
+ * each raw event filled.
+ * @max:   Maximum number of raw events to fill.
+ * @timings:   Pulse distance modulation timings.
+ * @n: Number of bits of data.
+ * @data:  Data bits to encode.
+ *
+ * Encodes the @n least significant bits of @data using pulse-distance
+ * modulation with the timing characteristics described by @timings, writing up
+ * to @max raw IR events using the *@ev pointer.
+ *
+ * Returns:0 on success.
+ * -ENOBUFS if there isn't enough space in the array to fit the
+ * full encoded data. In this case all @max events will have been
+ * written.
+ */
+int ir_raw_gen_pd(struct ir_raw_event **ev, unsigned int max,
+ const struct ir_raw_timings_pd *timings,
+ unsigned int n, unsigned int data)
+{
+   int i;
+   int ret;
+
+   if (timings-header_pulse) {
+   ret = ir_raw_gen_pulse_space(ev, max, timings-header_pulse,
+timings-header_space);
+   if (ret)
+   return ret;
+   }
+
+   if (timings-msb_first) {
+   for (i = n - 1; i = 0; --i) {
+   ret = ir_raw_gen_pulse_space(ev, max,
+   timings-bit_pulse,
+   timings-bit_space[(data  i)  1]);
+   if (ret)
+   return ret;
+   }
+   } else {
+   for (i = 0; i  n; ++i, data = 1) {
+   ret = ir_raw_gen_pulse_space(ev, max,
+   timings-bit_pulse,
+   timings-bit_space[data  1]);
+   if (ret)
+   return ret;
+   }
+   }
+
+   ret = ir_raw_gen_pulse_space(ev, max, timings-trailer_pulse,
+timings-trailer_space);
+   return ret;
+}
+EXPORT_SYMBOL(ir_raw_gen_pd);
+
+/**
  * ir_raw_encode_scancode() - Encode a scancode as raw events
  *
  * @protocols: permitted protocols
diff --git a/drivers/media/rc/rc-core-priv.h b/drivers/media/rc/rc-core-priv.h
index 8afb971..b55ae24 100644
--- a/drivers/media/rc/rc-core-priv.h
+++ b/drivers/media/rc/rc-core-priv.h
@@ -153,6 +153,69 @@ static inline bool is_timing_event(struct ir_raw_event ev)
 #define TO_US(duration)DIV_ROUND_CLOSEST((duration), 
1000)
 #define TO_STR(is_pulse)   ((is_pulse) ? pulse : space)
 
+/* functions for IR encoders */
+
+static inline void init_ir_raw_event_duration(struct ir_raw_event *ev,
+ unsigned int pulse,
+ u32 duration)
+{
+   init_ir_raw_event(ev);
+   ev-duration = duration;
+   ev-pulse = pulse;
+}
+
+/**
+ * ir_raw_gen_pulse_space() - generate pulse and space raw events.
+ * @ev:Pointer to pointer to next free raw event.
+ * Will be incremented for each raw event written.
+ * @max:   Pointer to number of raw events available in buffer.
+ * Will be decremented for each raw event written.
+ * @pulse_width:   Width of pulse in ns.
+ * @space_width:   Width of space in ns.
+ *
+ * Returns:0 on success.
+ * -ENOBUFS if there isn't enough buffer space to write

[PATCH v2 9/9] rc: nuvoton-cir: Add support for writing wakeup samples via sysfs filter callback

2014-03-14 Thread James Hogan
From: Antti Seppälä a.sepp...@gmail.com

Nuvoton-cir utilizes the encoding capabilities of rc-core to convert
scancodes from user space to pulse/space format understood by the
underlying hardware.

Converted samples are then written to the wakeup fifo along with other
necessary configuration to enable wake up functionality.

Signed-off-by: Antti Seppälä a.sepp...@gmail.com
Signed-off-by: James Hogan ja...@albanarts.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Jarod Wilson ja...@redhat.com
Cc: Wei Yongjun yongjun_...@trendmicro.com.cn
Cc: Hans Verkuil hans.verk...@cisco.com
---
Please note this patch is only build tested.

Changes in v2 (James Hogan):
 - Handle new -ENOBUFS when IR encoding buffer isn't long enough and
   reduce buffer size to the size of the wake fifo so that time isn't
   wasted processing encoded IR events that will be discarded. Also only
   discard the last event if the encoded data is complete.
 - Change reference to rc_dev::enabled_protocols to
   enabled_protocols[type] since it has been converted to an array.
 - Fix IR encoding buffer loop condition to be i  ret rather than i =
   ret. The return value of ir_raw_encode_scancode is the number of
   events rather than the last event.
 - Set encode_wakeup so that the set of allowed wakeup protocols matches
   the set of raw IR encoders.
---
 drivers/media/rc/nuvoton-cir.c | 123 +
 drivers/media/rc/nuvoton-cir.h |   1 +
 include/media/rc-core.h|   1 +
 3 files changed, 125 insertions(+)

diff --git a/drivers/media/rc/nuvoton-cir.c b/drivers/media/rc/nuvoton-cir.c
index d244e1a..ec8f4fc 100644
--- a/drivers/media/rc/nuvoton-cir.c
+++ b/drivers/media/rc/nuvoton-cir.c
@@ -527,6 +527,127 @@ static int nvt_set_tx_carrier(struct rc_dev *dev, u32 
carrier)
return 0;
 }
 
+static int nvt_write_wakeup_codes(struct rc_dev *dev,
+ const u8 *wakeup_sample_buf, int count)
+{
+   int i = 0;
+   u8 reg, reg_learn_mode;
+   unsigned long flags;
+   struct nvt_dev *nvt = dev-priv;
+
+   nvt_dbg_wake(writing wakeup samples);
+
+   reg = nvt_cir_wake_reg_read(nvt, CIR_WAKE_IRCON);
+   reg_learn_mode = reg  ~CIR_WAKE_IRCON_MODE0;
+   reg_learn_mode |= CIR_WAKE_IRCON_MODE1;
+
+   /* Lock the learn area to prevent racing with wake-isr */
+   spin_lock_irqsave(nvt-nvt_lock, flags);
+
+   /* Enable fifo writes */
+   nvt_cir_wake_reg_write(nvt, reg_learn_mode, CIR_WAKE_IRCON);
+
+   /* Clear cir wake rx fifo */
+   nvt_clear_cir_wake_fifo(nvt);
+
+   if (count  WAKE_FIFO_LEN) {
+   nvt_dbg_wake(HW FIFO too small for all wake samples);
+   count = WAKE_FIFO_LEN;
+   }
+
+   if (count)
+   pr_info(Wake samples (%d) =, count);
+   else
+   pr_info(Wake sample fifo cleared);
+
+   /* Write wake samples to fifo */
+   for (i = 0; i  count; i++) {
+   pr_cont( %02x, wakeup_sample_buf[i]);
+   nvt_cir_wake_reg_write(nvt, wakeup_sample_buf[i],
+  CIR_WAKE_WR_FIFO_DATA);
+   }
+   pr_cont(\n);
+
+   /* Switch cir to wakeup mode and disable fifo writing */
+   nvt_cir_wake_reg_write(nvt, reg, CIR_WAKE_IRCON);
+
+   /* Set number of bytes needed for wake */
+   nvt_cir_wake_reg_write(nvt, count ? count :
+  CIR_WAKE_FIFO_CMP_BYTES,
+  CIR_WAKE_FIFO_CMP_DEEP);
+
+   spin_unlock_irqrestore(nvt-nvt_lock, flags);
+
+   return 0;
+}
+
+static int nvt_ir_raw_set_filter(struct rc_dev *dev, enum rc_filter_type type,
+struct rc_scancode_filter *sc_filter)
+{
+   u8 *reg_buf;
+   u8 buf_val;
+   int i, ret, count;
+   unsigned int val;
+   struct ir_raw_event *raw;
+   bool complete;
+
+   /* Other types are not valid for nuvoton */
+   if (type != RC_FILTER_WAKEUP)
+   return -EINVAL;
+
+   /* Require both mask and data to be set before actually committing */
+   if (!sc_filter-mask || !sc_filter-data)
+   return 0;
+
+   raw = kmalloc(WAKE_FIFO_LEN * sizeof(*raw), GFP_KERNEL);
+   if (!raw)
+   return -ENOMEM;
+
+   ret = ir_raw_encode_scancode(dev-enabled_protocols[type], sc_filter,
+raw, WAKE_FIFO_LEN);
+   complete = (ret != -ENOBUFS);
+   if (!complete)
+   ret = WAKE_FIFO_LEN;
+   else if (ret  0)
+   goto out_raw;
+
+   reg_buf = kmalloc(sizeof(*reg_buf) * WAKE_FIFO_LEN, GFP_KERNEL);
+   if (!reg_buf) {
+   ret = -ENOMEM;
+   goto out_raw;
+   }
+
+   /* Inspect the ir samples */
+   for (i = 0, count = 0; i  ret  count  WAKE_FIFO_LEN; ++i) {
+   val = NS_TO_US((raw[i]).duration) / SAMPLE_PERIOD;
+
+   /* Split too large values into several smaller

[PATCH 1/3] rc: img-ir: hw: Remove unnecessary semi-colon

2014-03-13 Thread James Hogan
Fix a coccicheck warning in img-ir driver:
drivers/media/rc/img-ir/img-ir-hw.c:500:2-3: Unneeded semicolon

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
---
I don't object to this patch being squashed into the patch rc: img-ir:
add hardware decoder driver.
---
 drivers/media/rc/img-ir/img-ir-hw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
b/drivers/media/rc/img-ir/img-ir-hw.c
index cbbfd7df649f..2abf78a89fc5 100644
--- a/drivers/media/rc/img-ir/img-ir-hw.c
+++ b/drivers/media/rc/img-ir/img-ir-hw.c
@@ -497,7 +497,7 @@ set_unlock:
break;
default:
ret = -EINVAL;
-   };
+   }
 
 unlock:
spin_unlock_irq(priv-lock);
-- 
1.8.1.2

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/3] rc: img-ir: Fixes a few warnings

2014-03-13 Thread James Hogan
These patches fix a few warnings in the img-ir driver, one from
coccinelle and two more from W=1 (thanks Mauro).

James Hogan (3):
  rc: img-ir: hw: Remove unnecessary semi-colon
  rc: img-ir: hw: Fix min/max bits setup
  rc: img-ir: jvc: Remove unused no-leader timings

 drivers/media/rc/img-ir/img-ir-hw.c  |  8 
 drivers/media/rc/img-ir/img-ir-jvc.c | 11 ---
 2 files changed, 4 insertions(+), 15 deletions(-)

-- 
1.8.1.2

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/3] rc: img-ir: jvc: Remove unused no-leader timings

2014-03-13 Thread James Hogan
The JVC timings included timings intended for the secondary decoder
(which matches messages with no leader), however they were in the wrong
part of the timings structure, repeating s00 and s01 rather than being
in s10 and s11.

Distinct repeat timings can't be properly supported yet for JVC anyway
since the scancode callback cannot determine which decoder matched the
message, so for now remove these timings and don't bother to enable the
secondary decoder.

This fixes the following warnings with W=1:
drivers/media/rc/img-ir/img-ir-jvc.c +76 :3: warning: initialized field 
overwritten [-Woverride-init]
drivers/media/rc/img-ir/img-ir-jvc.c +76 :3: warning: (near initialization for 
‘img_ir_jvc.timings.s00’) [-Woverride-init]
drivers/media/rc/img-ir/img-ir-jvc.c +81 :3: warning: initialized field 
overwritten [-Woverride-init]
drivers/media/rc/img-ir/img-ir-jvc.c +81 :3: warning: (near initialization for 
‘img_ir_jvc.timings.s01’) [-Woverride-init]

Reported-by: Mauro Carvalho Chehab m.che...@samsung.com
Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
---
I don't object to this patch being squashed into the patch rc: img-ir:
add JVC decoder module.
---
 drivers/media/rc/img-ir/img-ir-jvc.c | 11 ---
 1 file changed, 11 deletions(-)

diff --git a/drivers/media/rc/img-ir/img-ir-jvc.c 
b/drivers/media/rc/img-ir/img-ir-jvc.c
index ae55867f6c5c..10209d200efb 100644
--- a/drivers/media/rc/img-ir/img-ir-jvc.c
+++ b/drivers/media/rc/img-ir/img-ir-jvc.c
@@ -49,7 +49,6 @@ struct img_ir_decoder img_ir_jvc = {
.control = {
.decoden = 1,
.code_type = IMG_IR_CODETYPE_PULSEDIST,
-   .decodend2 = 1,
},
/* main timings */
.unit = 527500, /* 527.5 us */
@@ -69,16 +68,6 @@ struct img_ir_decoder img_ir_jvc = {
.pulse = { 1/* 527.5 us +-60 us */ },
.space = { 3/* 1.5825 ms +-40 us */ },
},
-   /* 0 symbol (no leader) */
-   .s00 = {
-   .pulse = { 1/* 527.5 us +-60 us */ },
-   .space = { 1/* 527.5 us */ },
-   },
-   /* 1 symbol (no leader) */
-   .s01 = {
-   .pulse = { 1/* 527.5 us +-60 us */ },
-   .space = { 3/* 1.5825 ms +-40 us */ },
-   },
/* free time */
.ft = {
.minlen = 16,
-- 
1.8.1.2

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/3] rc: img-ir: hw: Fix min/max bits setup

2014-03-13 Thread James Hogan
The calculated values for the minlen and maxlen fields, which were
rounded to multiples of 2 and clamped to a valid range, were left
unused. Use them in the calculation of the register value rather than
using the raw input minlen and maxlen.

This fixes the following warning with a W=1 build:
drivers/media/rc/img-ir/img-ir-hw.c In function ‘img_ir_free_timing’:
drivers/media/rc/img-ir/img-ir-hw.c +228 :23: warning: variable ‘maxlen’ set 
but not used [-Wunused-but-set-variable]
drivers/media/rc/img-ir/img-ir-hw.c +228 :15: warning: variable ‘minlen’ set 
but not used [-Wunused-but-set-variable]

Reported-by: Mauro Carvalho Chehab m.che...@samsung.com
Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
---
I don't object to this patch being squashed into the patch rc: img-ir:
add hardware decoder driver.
---
 drivers/media/rc/img-ir/img-ir-hw.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
b/drivers/media/rc/img-ir/img-ir-hw.c
index 2abf78a89fc5..579a52b3edce 100644
--- a/drivers/media/rc/img-ir/img-ir-hw.c
+++ b/drivers/media/rc/img-ir/img-ir-hw.c
@@ -240,9 +240,9 @@ static u32 img_ir_free_timing(const struct 
img_ir_free_timing *timing,
ft_min = (timing-ft_min*clock_hz + 99) / 100;
ft_min = (ft_min + 7)  3;
/* construct register value */
-   return  (timing-maxlen  IMG_IR_MAXLEN_SHIFT) |
-   (timing-minlen  IMG_IR_MINLEN_SHIFT) |
-   (ft_min  IMG_IR_FT_MIN_SHIFT);
+   return  (maxlen  IMG_IR_MAXLEN_SHIFT) |
+   (minlen  IMG_IR_MINLEN_SHIFT) |
+   (ft_min  IMG_IR_FT_MIN_SHIFT);
 }
 
 /**
-- 
1.8.1.2

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4 10/10] rc: img-ir: add Sanyo decoder module

2014-03-12 Thread James Hogan
On 12/03/14 10:57, Mauro Carvalho Chehab wrote:
 Hi James,
 
 Em Fri, 28 Feb 2014 23:29:00 +
 James Hogan james.ho...@imgtec.com escreveu:
 
 Add an img-ir module for decoding the Sanyo infrared protocol.
 
 After applying this series, some new warnings are popping up,
 when compiled with W=1:
 
 drivers/media/rc/img-ir/img-ir-hw.c: In function 'img_ir_free_timing':
 drivers/media/rc/img-ir/img-ir-hw.c:228:23: warning: variable 'maxlen' set 
 but not used [-Wunused-but-set-variable]
   unsigned int minlen, maxlen, ft_min;
^
 drivers/media/rc/img-ir/img-ir-hw.c:228:15: warning: variable 'minlen' set 
 but not used [-Wunused-but-set-variable]
   unsigned int minlen, maxlen, ft_min;
^
 drivers/media/rc/img-ir/img-ir-jvc.c:76:3: warning: initialized field 
 overwritten [-Woverride-init]
},
^
 drivers/media/rc/img-ir/img-ir-jvc.c:76:3: warning: (near initialization for 
 'img_ir_jvc.timings.s00') [-Woverride-init]
 drivers/media/rc/img-ir/img-ir-jvc.c:81:3: warning: initialized field 
 overwritten [-Woverride-init]
},
^
 drivers/media/rc/img-ir/img-ir-jvc.c:81:3: warning: (near initialization for 
 'img_ir_jvc.timings.s01') [-Woverride-init]
 
 Please fix.

Ooh yes, I hadn't tried W=1. Both appear to indicate genuine bugs. I'll
fix and do a retest later today.

Thanks
James
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/5] rc: scancode filtering improvements

2014-03-05 Thread James Hogan
Hi Antti,

On Wednesday 05 March 2014 20:12:15 Antti Seppälä wrote:
 After reviewing the series and porting my nuvoton changes to it I
 haven't noticed any errors worth mentioning.
 In fact I think this series is very well written and should be merged.

Thanks for reviewing!

 James, I hope you also have the time to submit the ir encoder series
 for inclusion. :)

I did a little work on it the other day, including adding encode+loopback on 
filter change to loopback driver, fixing a few bugs and adding RC-5/RC-5X 
encode. I'll probably see what I can do to add partial encode to be sure the 
API doesn't fall short and then send a combined patchset.

Cheers
James

signature.asc
Description: This is a digitally signed message part.


[PATCH] rc-main: fix missing unlock if no devno left

2014-03-01 Thread James Hogan
While playing with make coccicheck I noticed this message:
drivers/media/rc/rc-main.c:1245:3-9: preceding lock on line 1238

It was introduced by commit 587d1b06e07b ([media] rc-core: reuse device
numbers) which returns -ENOMEM after a mutex_lock without first
unlocking it when there are no more device numbers left. The added code
doesn't depend on the device lock, so move it before the lock is taken.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: linux-media@vger.kernel.org
---
 drivers/media/rc/rc-main.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 2ec60f8..79bcd41 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -1228,24 +1228,24 @@ int rc_register_device(struct rc_dev *dev)
dev-input_dev-open = ir_open;
if (dev-close)
dev-input_dev-close = ir_close;
 
-   /*
-* Take the lock here, as the device sysfs node will appear
-* when device_add() is called, which may trigger an ir-keytable udev
-* rule, which will in turn call show_protocols and access
-* dev-enabled_protocols before it has been initialized.
-*/
-   mutex_lock(dev-lock);
-
do {
devno = find_first_zero_bit(ir_core_dev_number,
IRRCV_NUM_DEVICES);
/* No free device slots */
if (devno = IRRCV_NUM_DEVICES)
return -ENOMEM;
} while (test_and_set_bit(devno, ir_core_dev_number));
 
+   /*
+* Take the lock here, as the device sysfs node will appear
+* when device_add() is called, which may trigger an ir-keytable udev
+* rule, which will in turn call show_protocols and access
+* dev-enabled_protocols before it has been initialized.
+*/
+   mutex_lock(dev-lock);
+
dev-devno = devno;
dev_set_name(dev-dev, rc%ld, dev-devno);
dev_set_drvdata(dev-dev, dev);
rc = device_add(dev-dev);
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 06/15] dt: binding: add binding for ImgTec IR block

2014-02-28 Thread James Hogan
On 28/02/14 01:28, Rob Herring wrote:
 On Thu, Feb 27, 2014 at 4:52 PM, James Hogan james.ho...@imgtec.com wrote:
 v3:
 - Rename compatible string to img,ir-rev1 (Rob Herring).
 - Specify ordering of clocks explicitly (Rob Herring).

 I'd appreciate if somebody could give this another glance after the two
 changes listed above and Ack it (I'll probably be posting a v4 patchset
 tomorrow).
 
 Looks fine.
 
 Acked-by: Rob Herring r...@kernel.org

Thanks Rob!

Cheers
James
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/5] rc-main: add generic scancode filtering

2014-02-28 Thread James Hogan
Add generic scancode filtering of RC input events, and fall back to
permitting any RC_FILTER_NORMAL scancode filter to be set if no s_filter
callback exists. This allows raw IR decoder events to be filtered, and
potentially allows hardware decoders to set looser filters and rely on
generic code to filter out the corner cases.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Antti Seppälä a.sepp...@gmail.com
Cc: linux-media@vger.kernel.org
---
 drivers/media/rc/rc-main.c | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 6448128..0a4f680 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -633,6 +633,7 @@ EXPORT_SYMBOL_GPL(rc_repeat);
 static void ir_do_keydown(struct rc_dev *dev, int scancode,
  u32 keycode, u8 toggle)
 {
+   struct rc_scancode_filter *filter;
bool new_event = !dev-keypressed ||
 dev-last_scancode != scancode ||
 dev-last_toggle != toggle;
@@ -640,6 +641,11 @@ static void ir_do_keydown(struct rc_dev *dev, int scancode,
if (new_event  dev-keypressed)
ir_do_keyup(dev, false);
 
+   /* Generic scancode filtering */
+   filter = dev-scancode_filters[RC_FILTER_NORMAL];
+   if (filter-mask  ((scancode ^ filter-data)  filter-mask))
+   return;
+
input_event(dev-input_dev, EV_MSC, MSC_SCAN, scancode);
 
if (new_event  keycode != KEY_RESERVED) {
@@ -1019,9 +1025,7 @@ static ssize_t show_filter(struct device *device,
return -EINVAL;
 
mutex_lock(dev-lock);
-   if (!dev-s_filter)
-   val = 0;
-   else if (fattr-mask)
+   if (fattr-mask)
val = dev-scancode_filters[fattr-type].mask;
else
val = dev-scancode_filters[fattr-type].data;
@@ -1069,7 +1073,7 @@ static ssize_t store_filter(struct device *device,
return ret;
 
/* Scancode filter not supported (but still accept 0) */
-   if (!dev-s_filter)
+   if (!dev-s_filter  fattr-type != RC_FILTER_NORMAL)
return val ? -EINVAL : count;
 
mutex_lock(dev-lock);
@@ -1081,9 +1085,11 @@ static ssize_t store_filter(struct device *device,
local_filter.mask = val;
else
local_filter.data = val;
-   ret = dev-s_filter(dev, fattr-type, local_filter);
-   if (ret  0)
-   goto unlock;
+   if (dev-s_filter) {
+   ret = dev-s_filter(dev, fattr-type, local_filter);
+   if (ret  0)
+   goto unlock;
+   }
 
/* Success, commit the new filter */
*filter = local_filter;
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/5] rc: add allowed/enabled wakeup protocol masks

2014-02-28 Thread James Hogan
Only a single allowed and enabled protocol mask currently exists in
struct rc_dev, however to support a separate wakeup filter protocol two
of each are needed, ideally as an array.

Therefore make both rc_dev::allowed_protos and rc_dev::enabled_protocols
arrays, update all users to reference the first element
(RC_FILTER_NORMAL), and add a couple more helper functions for drivers
to use for setting the allowed and enabled wakeup protocols.

We also rename allowed_protos to allowed_protocols while we're at it,
which is more consistent with enabled_protocols.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Antti Seppälä a.sepp...@gmail.com
Cc: linux-media@vger.kernel.org
---
 drivers/media/rc/rc-main.c | 10 +-
 include/media/rc-core.h| 32 
 2 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 0a4f680..309d791 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -830,9 +830,9 @@ static ssize_t show_protocols(struct device *device,
 
mutex_lock(dev-lock);
 
-   enabled = dev-enabled_protocols;
+   enabled = dev-enabled_protocols[RC_FILTER_NORMAL];
if (dev-driver_type == RC_DRIVER_SCANCODE)
-   allowed = dev-allowed_protos;
+   allowed = dev-allowed_protocols[RC_FILTER_NORMAL];
else if (dev-raw)
allowed = ir_raw_get_allowed_protocols();
else {
@@ -906,7 +906,7 @@ static ssize_t store_protocols(struct device *device,
ret = -EINVAL;
goto out;
}
-   type = dev-enabled_protocols;
+   type = dev-enabled_protocols[RC_FILTER_NORMAL];
 
while ((tmp = strsep((char **) data,  \n)) != NULL) {
if (!*tmp)
@@ -964,7 +964,7 @@ static ssize_t store_protocols(struct device *device,
}
}
 
-   dev-enabled_protocols = type;
+   dev-enabled_protocols[RC_FILTER_NORMAL] = type;
IR_dprintk(1, Current protocol(s): 0x%llx\n,
   (long long)type);
 
@@ -1316,7 +1316,7 @@ int rc_register_device(struct rc_dev *dev)
rc = dev-change_protocol(dev, rc_type);
if (rc  0)
goto out_raw;
-   dev-enabled_protocols = rc_type;
+   dev-enabled_protocols[RC_FILTER_NORMAL] = rc_type;
}
 
mutex_unlock(dev-lock);
diff --git a/include/media/rc-core.h b/include/media/rc-core.h
index 6f3c3d9..f165115 100644
--- a/include/media/rc-core.h
+++ b/include/media/rc-core.h
@@ -73,8 +73,10 @@ enum rc_filter_type {
  * @input_dev: the input child device used to communicate events to userspace
  * @driver_type: specifies if protocol decoding is done in hardware or software
  * @idle: used to keep track of RX state
- * @allowed_protos: bitmask with the supported RC_BIT_* protocols
- * @enabled_protocols: bitmask with the enabled RC_BIT_* protocols
+ * @allowed_protocols: bitmask with the supported RC_BIT_* protocols for each
+ * filter type
+ * @enabled_protocols: bitmask with the enabled RC_BIT_* protocols for each
+ * filter type
  * @scanmask: some hardware decoders are not capable of providing the full
  * scancode to the application. As this is a hardware limit, we can't do
  * anything with it. Yet, as the same keycode table can be used with other
@@ -124,8 +126,8 @@ struct rc_dev {
struct input_dev*input_dev;
enum rc_driver_type driver_type;
boolidle;
-   u64 allowed_protos;
-   u64 enabled_protocols;
+   u64 allowed_protocols[RC_FILTER_MAX];
+   u64 enabled_protocols[RC_FILTER_MAX];
u32 users;
u32 scanmask;
void*priv;
@@ -162,24 +164,38 @@ struct rc_dev {
 
 static inline bool rc_protocols_allowed(struct rc_dev *rdev, u64 protos)
 {
-   return rdev-allowed_protos  protos;
+   return rdev-allowed_protocols[RC_FILTER_NORMAL]  protos;
 }
 
 /* should be called prior to registration or with mutex held */
 static inline void rc_set_allowed_protocols(struct rc_dev *rdev, u64 protos)
 {
-   rdev-allowed_protos = protos;
+   rdev-allowed_protocols[RC_FILTER_NORMAL] = protos;
 }
 
 static inline bool rc_protocols_enabled(struct rc_dev *rdev, u64 protos)
 {
-   return rdev-enabled_protocols  protos;
+   return rdev-enabled_protocols[RC_FILTER_NORMAL]  protos;
 }
 
 /* should be called prior to registration or with mutex held */
 static inline void rc_set_enabled_protocols(struct rc_dev *rdev, u64 protos)
 {
-   rdev-enabled_protocols = protos;
+   rdev-enabled_protocols[RC_FILTER_NORMAL] = protos;
+}
+
+/* should be called

[PATCH 5/5] rc-main: automatically refresh filter on protocol change

2014-02-28 Thread James Hogan
When either of the normal or wakeup filter protocols are changed,
refresh the corresponding scancode filter, i.e. try and set the same
scancode filter with the new protocol. If that fails clear the filter
instead.

If no protocol was selected the filter is just cleared, and if no
s_filter callback exists the filter is left unmodified.

Similarly clear the filter mask when the filter is set if no protocol is
currently selected.

This simplifies driver code which no longer has to explicitly worry
about modifying the filter on a protocol change. This also allows the
change_wakeup_protocol callback to be omitted entirely if there is only
a single available wakeup protocol at a time, since selecting no
protocol will automatically clear the wakeup filter, disabling wakeup.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Antti Seppälä a.sepp...@gmail.com
Cc: linux-media@vger.kernel.org
---
 drivers/media/rc/rc-main.c | 41 +++--
 1 file changed, 39 insertions(+), 2 deletions(-)

diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index e6e3ec7..b1a6900 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -918,11 +918,12 @@ static ssize_t store_protocols(struct device *device,
struct rc_filter_attribute *fattr = to_rc_filter_attr(mattr);
bool enable, disable;
const char *tmp;
-   u64 type;
+   u64 old_type, type;
u64 mask;
int rc, i, count = 0;
ssize_t ret;
int (*change_protocol)(struct rc_dev *dev, u64 *rc_type);
+   struct rc_scancode_filter local_filter, *filter;
 
/* Device is being removed */
if (!dev)
@@ -935,7 +936,8 @@ static ssize_t store_protocols(struct device *device,
ret = -EINVAL;
goto out;
}
-   type = dev-enabled_protocols[fattr-type];
+   old_type = dev-enabled_protocols[fattr-type];
+   type = old_type;
 
while ((tmp = strsep((char **) data,  \n)) != NULL) {
if (!*tmp)
@@ -999,6 +1001,36 @@ static ssize_t store_protocols(struct device *device,
IR_dprintk(1, Current protocol(s): 0x%llx\n,
   (long long)type);
 
+   /*
+* If the protocol is changed the filter needs updating.
+* Try setting the same filter with the new protocol (if any).
+* Fall back to clearing the filter.
+*/
+   filter = dev-scancode_filters[fattr-type];
+   if (old_type != type  filter-mask) {
+   local_filter = *filter;
+   if (!type) {
+   /* no protocol = clear filter */
+   ret = -1;
+   } else if (!dev-s_filter) {
+   /* generic filtering = accept any filter */
+   ret = 0;
+   } else {
+   /* hardware filtering = try setting, otherwise clear */
+   ret = dev-s_filter(dev, fattr-type, local_filter);
+   }
+   if (ret  0) {
+   /* clear the filter */
+   local_filter.data = 0;
+   local_filter.mask = 0;
+   if (dev-s_filter)
+   dev-s_filter(dev, fattr-type, local_filter);
+   }
+
+   /* commit the new filter */
+   *filter = local_filter;
+   }
+
ret = len;
 
 out:
@@ -1096,6 +1128,11 @@ static ssize_t store_filter(struct device *device,
local_filter.mask = val;
else
local_filter.data = val;
+   if (!dev-enabled_protocols[fattr-type]  local_filter.mask) {
+   /* refuse to set a filter unless a protocol is enabled */
+   ret = -EINVAL;
+   goto unlock;
+   }
if (dev-s_filter) {
ret = dev-s_filter(dev, fattr-type, local_filter);
if (ret  0)
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/5] rc: add wakeup_protocols sysfs file

2014-02-28 Thread James Hogan
Add a wakeup_protocols sysfs file which controls the new
rc_dev::enabled_protocols[RC_FILTER_WAKEUP], which is the mask of
protocols that are used for the wakeup filter.

A new RC driver callback change_wakeup_protocol() is called to change
the wakeup protocol mask.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Antti Seppälä a.sepp...@gmail.com
Cc: Rob Landley r...@landley.net
Cc: linux-media@vger.kernel.org
Cc: linux-...@vger.kernel.org
---
 Documentation/ABI/testing/sysfs-class-rc   | 23 +-
 .../DocBook/media/v4l/remote_controllers.xml   | 20 +-
 drivers/media/rc/rc-main.c | 82 +-
 include/media/rc-core.h|  3 +
 4 files changed, 90 insertions(+), 38 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-class-rc 
b/Documentation/ABI/testing/sysfs-class-rc
index c0e1d14..b65674d 100644
--- a/Documentation/ABI/testing/sysfs-class-rc
+++ b/Documentation/ABI/testing/sysfs-class-rc
@@ -61,6 +61,25 @@ Description:
an error.
This value may be reset to 0 if the current protocol is altered.
 
+What:  /sys/class/rc/rcN/wakeup_protocols
+Date:  Feb 2014
+KernelVersion: 3.15
+Contact:   Mauro Carvalho Chehab m.che...@samsung.com
+Description:
+   Reading this file returns a list of available protocols to use
+   for the wakeup filter, something like:
+   rc5 rc6 nec jvc [sony]
+   The enabled wakeup protocol is shown in [] brackets.
+   Writing +proto will add a protocol to the list of enabled
+   wakeup protocols.
+   Writing -proto will remove a protocol from the list of enabled
+   wakeup protocols.
+   Writing proto will use proto for wakeup events.
+   Writing none will disable wakeup.
+   Write fails with EINVAL if an invalid protocol combination or
+   unknown protocol name is used, or if wakeup is not supported by
+   the hardware.
+
 What:  /sys/class/rc/rcN/wakeup_filter
 Date:  Jan 2014
 KernelVersion: 3.15
@@ -74,7 +93,7 @@ Description:
scancodes which match the filter will wake the system from e.g.
suspend to RAM or power off.
Otherwise the write will fail with an error.
-   This value may be reset to 0 if the current protocol is altered.
+   This value may be reset to 0 if the wakeup protocol is altered.
 
 What:  /sys/class/rc/rcN/wakeup_filter_mask
 Date:  Jan 2014
@@ -89,4 +108,4 @@ Description:
scancodes which match the filter will wake the system from e.g.
suspend to RAM or power off.
Otherwise the write will fail with an error.
-   This value may be reset to 0 if the current protocol is altered.
+   This value may be reset to 0 if the wakeup protocol is altered.
diff --git a/Documentation/DocBook/media/v4l/remote_controllers.xml 
b/Documentation/DocBook/media/v4l/remote_controllers.xml
index c440a81..5124a6c 100644
--- a/Documentation/DocBook/media/v4l/remote_controllers.xml
+++ b/Documentation/DocBook/media/v4l/remote_controllers.xml
@@ -102,6 +102,22 @@ an error./para
 paraThis value may be reset to 0 if the current protocol is altered./para
 
 /section
+section id=sys_class_rc_rcN_wakeup_protocols
+title/sys/class/rc/rcN/wakeup_protocols/title
+paraReading this file returns a list of available protocols to use for the
+wakeup filter, something like:/para
+paraconstantrc5 rc6 nec jvc [sony]/constant/para
+paraThe enabled wakeup protocol is shown in [] brackets./para
+paraWriting +proto will add a protocol to the list of enabled wakeup
+protocols./para
+paraWriting -proto will remove a protocol from the list of enabled wakeup
+protocols./para
+paraWriting proto will use proto for wakeup events./para
+paraWriting none will disable wakeup./para
+paraWrite fails with EINVAL if an invalid protocol combination or unknown
+protocol name is used, or if wakeup is not supported by the hardware./para
+
+/section
 section id=sys_class_rc_rcN_wakeup_filter
 title/sys/class/rc/rcN/wakeup_filter/title
 paraSets the scancode wakeup filter expected value.
@@ -112,7 +128,7 @@ to trigger a system wake event./para
 scancodes which match the filter will wake the system from e.g.
 suspend to RAM or power off.
 Otherwise the write will fail with an error./para
-paraThis value may be reset to 0 if the current protocol is altered./para
+paraThis value may be reset to 0 if the wakeup protocol is altered./para
 
 /section
 section id=sys_class_rc_rcN_wakeup_filter_mask
@@ -125,7 +141,7 @@ expected value to trigger a system wake event./para
 scancodes which match the filter will wake the system from e.g.
 suspend to RAM or power off.
 Otherwise the write will fail with an error./para

[PATCH 2/5] rc: abstract access to allowed/enabled protocols

2014-02-28 Thread James Hogan
The allowed and enabled protocol masks need to be expanded to be per
filter type in order to support wakeup filter protocol selection. To
ease that process abstract access to the rc_dev::allowed_protos and
rc_dev::enabled_protocols members with inline functions.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Bruno Prémont bonb...@linux-vserver.org
Cc: Maxim Levitsky maximlevit...@gmail.com
Cc: Sean Young s...@mess.org
Cc: David Härdeman da...@hardeman.nu
Cc: Jiri Kosina jkos...@suse.cz
Cc: Antti Seppälä a.sepp...@gmail.com
Cc: linux-media@vger.kernel.org
---
 drivers/hid/hid-picolcd_cir.c   |  2 +-
 drivers/media/common/siano/smsir.c  |  2 +-
 drivers/media/i2c/ir-kbd-i2c.c  |  4 ++--
 drivers/media/pci/cx23885/cx23885-input.c   |  2 +-
 drivers/media/pci/cx88/cx88-input.c |  2 +-
 drivers/media/rc/ati_remote.c   |  2 +-
 drivers/media/rc/ene_ir.c   |  2 +-
 drivers/media/rc/fintek-cir.c   |  2 +-
 drivers/media/rc/gpio-ir-recv.c |  4 ++--
 drivers/media/rc/iguanair.c |  2 +-
 drivers/media/rc/imon.c |  7 ---
 drivers/media/rc/ir-jvc-decoder.c   |  2 +-
 drivers/media/rc/ir-lirc-codec.c|  2 +-
 drivers/media/rc/ir-mce_kbd-decoder.c   |  2 +-
 drivers/media/rc/ir-nec-decoder.c   |  2 +-
 drivers/media/rc/ir-raw.c   |  2 +-
 drivers/media/rc/ir-rc5-decoder.c   |  6 +++---
 drivers/media/rc/ir-rc5-sz-decoder.c|  2 +-
 drivers/media/rc/ir-rc6-decoder.c   |  6 +++---
 drivers/media/rc/ir-sanyo-decoder.c |  2 +-
 drivers/media/rc/ir-sharp-decoder.c |  2 +-
 drivers/media/rc/ir-sony-decoder.c  | 10 +-
 drivers/media/rc/ite-cir.c  |  2 +-
 drivers/media/rc/mceusb.c   |  2 +-
 drivers/media/rc/nuvoton-cir.c  |  2 +-
 drivers/media/rc/rc-loopback.c  |  2 +-
 drivers/media/rc/redrat3.c  |  2 +-
 drivers/media/rc/st_rc.c|  2 +-
 drivers/media/rc/streamzap.c|  2 +-
 drivers/media/rc/ttusbir.c  |  2 +-
 drivers/media/rc/winbond-cir.c  |  2 +-
 drivers/media/usb/dvb-usb-v2/dvb_usb_core.c |  2 +-
 drivers/media/usb/dvb-usb/dvb-usb-remote.c  |  2 +-
 drivers/media/usb/em28xx/em28xx-input.c |  8 
 drivers/media/usb/tm6000/tm6000-input.c |  2 +-
 include/media/rc-core.h | 22 ++
 36 files changed, 73 insertions(+), 50 deletions(-)

diff --git a/drivers/hid/hid-picolcd_cir.c b/drivers/hid/hid-picolcd_cir.c
index 59d5eb1..cf1a9f1 100644
--- a/drivers/hid/hid-picolcd_cir.c
+++ b/drivers/hid/hid-picolcd_cir.c
@@ -114,7 +114,7 @@ int picolcd_init_cir(struct picolcd_data *data, struct 
hid_report *report)
 
rdev-priv = data;
rdev-driver_type  = RC_DRIVER_IR_RAW;
-   rdev-allowed_protos   = RC_BIT_ALL;
+   rc_set_allowed_protocols(rdev, RC_BIT_ALL);
rdev-open = picolcd_cir_open;
rdev-close= picolcd_cir_close;
rdev-input_name   = data-hdev-name;
diff --git a/drivers/media/common/siano/smsir.c 
b/drivers/media/common/siano/smsir.c
index b8c5cad..6d7c0c8 100644
--- a/drivers/media/common/siano/smsir.c
+++ b/drivers/media/common/siano/smsir.c
@@ -88,7 +88,7 @@ int sms_ir_init(struct smscore_device_t *coredev)
 
dev-priv = coredev;
dev-driver_type = RC_DRIVER_IR_RAW;
-   dev-allowed_protos = RC_BIT_ALL;
+   rc_set_allowed_protocols(dev, RC_BIT_ALL);
dev-map_name = sms_get_board(board_id)-rc_codes;
dev-driver_name = MODULE_NAME;
 
diff --git a/drivers/media/i2c/ir-kbd-i2c.c b/drivers/media/i2c/ir-kbd-i2c.c
index 99ee456..c8fe135 100644
--- a/drivers/media/i2c/ir-kbd-i2c.c
+++ b/drivers/media/i2c/ir-kbd-i2c.c
@@ -431,8 +431,8 @@ static int ir_probe(struct i2c_client *client, const struct 
i2c_device_id *id)
 * Initialize the other fields of rc_dev
 */
rc-map_name   = ir-ir_codes;
-   rc-allowed_protos = rc_type;
-   rc-enabled_protocols = rc_type;
+   rc_set_allowed_protocols(rc, rc_type);
+   rc_set_enabled_protocols(rc, rc_type);
if (!rc-driver_name)
rc-driver_name = MODULE_NAME;
 
diff --git a/drivers/media/pci/cx23885/cx23885-input.c 
b/drivers/media/pci/cx23885/cx23885-input.c
index 8a49e7c..097d0a0 100644
--- a/drivers/media/pci/cx23885/cx23885-input.c
+++ b/drivers/media/pci/cx23885/cx23885-input.c
@@ -346,7 +346,7 @@ int cx23885_input_init(struct cx23885_dev *dev)
}
rc-dev.parent = dev-pci-dev;
rc-driver_type = driver_type;
-   rc-allowed_protos = allowed_protos;
+   rc_set_allowed_protocols(rc, allowed_protos);
rc-priv = kernel_ir;
rc-open = cx23885_input_ir_open;
rc-close = cx23885_input_ir_close;
diff

[PATCH 0/5] rc: scancode filtering improvements

2014-02-28 Thread James Hogan
These patches make some improvements relating to the recently added RC
scancode filtering interface:
- Patch 1 adds generic scancode filtering. This allows filtering to also
  work for raw rc drivers and scancode drivers without filtering
  capabilities.
- Patches 2-4 future proof the sysfs API to allow a different wakeup
  filter protocol to be set than the current protocol. A new
  wakeup_protocols sysfs file is added which behaves similarly to the
  protocols sysfs file but applies only to wakeup filters.
- Finally patch 5 improves the driver interface so that changing either
  the normal or wakeup protocol automatically causes the corresponding
  filter to be refreshed to the driver, or failing that cleared. It also
  ensures that the filter is turned off (and for wakeup that means
  wakeup is disabled) if the protocol is set to none. This avoids the
  driver having to maintain the filters, or even need a
  change_wakeup_protocol() callback if there is only one wakeup protocol
  allowed at a time.

The patch rc-main: store_filter: pass errors to userland should
probably be applied first.

An updated img-ir v4 patchset which depends on this one will follow
soon.

Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Bruno Prémont bonb...@linux-vserver.org
Cc: Maxim Levitsky maximlevit...@gmail.com
Cc: Sean Young s...@mess.org
Cc: David Härdeman da...@hardeman.nu
Cc: Jiri Kosina jkos...@suse.cz
Cc: Antti Seppälä a.sepp...@gmail.com

James Hogan (5):
  rc-main: add generic scancode filtering
  rc: abstract access to allowed/enabled protocols
  rc: add allowed/enabled wakeup protocol masks
  rc: add wakeup_protocols sysfs file
  rc-main: automatically refresh filter on protocol change

 Documentation/ABI/testing/sysfs-class-rc   |  23 +++-
 .../DocBook/media/v4l/remote_controllers.xml   |  20 ++-
 drivers/hid/hid-picolcd_cir.c  |   2 +-
 drivers/media/common/siano/smsir.c |   2 +-
 drivers/media/i2c/ir-kbd-i2c.c |   4 +-
 drivers/media/pci/cx23885/cx23885-input.c  |   2 +-
 drivers/media/pci/cx88/cx88-input.c|   2 +-
 drivers/media/rc/ati_remote.c  |   2 +-
 drivers/media/rc/ene_ir.c  |   2 +-
 drivers/media/rc/fintek-cir.c  |   2 +-
 drivers/media/rc/gpio-ir-recv.c|   4 +-
 drivers/media/rc/iguanair.c|   2 +-
 drivers/media/rc/imon.c|   7 +-
 drivers/media/rc/ir-jvc-decoder.c  |   2 +-
 drivers/media/rc/ir-lirc-codec.c   |   2 +-
 drivers/media/rc/ir-mce_kbd-decoder.c  |   2 +-
 drivers/media/rc/ir-nec-decoder.c  |   2 +-
 drivers/media/rc/ir-raw.c  |   2 +-
 drivers/media/rc/ir-rc5-decoder.c  |   6 +-
 drivers/media/rc/ir-rc5-sz-decoder.c   |   2 +-
 drivers/media/rc/ir-rc6-decoder.c  |   6 +-
 drivers/media/rc/ir-sanyo-decoder.c|   2 +-
 drivers/media/rc/ir-sharp-decoder.c|   2 +-
 drivers/media/rc/ir-sony-decoder.c |  10 +-
 drivers/media/rc/ite-cir.c |   2 +-
 drivers/media/rc/mceusb.c  |   2 +-
 drivers/media/rc/nuvoton-cir.c |   2 +-
 drivers/media/rc/rc-loopback.c |   2 +-
 drivers/media/rc/rc-main.c | 141 +++--
 drivers/media/rc/redrat3.c |   2 +-
 drivers/media/rc/st_rc.c   |   2 +-
 drivers/media/rc/streamzap.c   |   2 +-
 drivers/media/rc/ttusbir.c |   2 +-
 drivers/media/rc/winbond-cir.c |   2 +-
 drivers/media/usb/dvb-usb-v2/dvb_usb_core.c|   2 +-
 drivers/media/usb/dvb-usb/dvb-usb-remote.c |   2 +-
 drivers/media/usb/em28xx/em28xx-input.c|   8 +-
 drivers/media/usb/tm6000/tm6000-input.c|   2 +-
 include/media/rc-core.h|  49 ++-
 39 files changed, 234 insertions(+), 100 deletions(-)

-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 00/10] media: rc: ImgTec IR decoder driver

2014-02-28 Thread James Hogan
 to extended NEC even when the high
  bits of the scancode value aren't set, by taking the mask into account
  too. My TV remote happens to use extended NEC with address 0x7f00,
  which unfortunately maps to scancodes 0x007f** which looks like normal
  NEC and couldn't previously be filtered.

Sharp decoder:
- Fix typo in logic 1 pulse width comment.
- Set tolerance to 20%, which seemed to be needed for the cases I have.

Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: Jarod Wilson ja...@redhat.com
Cc: linux-media@vger.kernel.org
Cc: Grant Likely grant.lik...@linaro.org
Cc: Rob Herring robh...@kernel.org
Cc: devicet...@vger.kernel.org
Cc: Rob Landley r...@landley.net
Cc: linux-...@vger.kernel.org
Cc: Tomasz Figa tomasz.f...@gmail.com

James Hogan (10):
  dt: binding: add binding for ImgTec IR block
  rc: img-ir: add base driver
  rc: img-ir: add raw driver
  rc: img-ir: add hardware decoder driver
  rc: img-ir: add to build
  rc: img-ir: add NEC decoder module
  rc: img-ir: add JVC decoder module
  rc: img-ir: add Sony decoder module
  rc: img-ir: add Sharp decoder module
  rc: img-ir: add Sanyo decoder module

 .../devicetree/bindings/media/img-ir-rev1.txt  |   34 +
 drivers/media/rc/Kconfig   |2 +
 drivers/media/rc/Makefile  |1 +
 drivers/media/rc/img-ir/Kconfig|   61 ++
 drivers/media/rc/img-ir/Makefile   |   11 +
 drivers/media/rc/img-ir/img-ir-core.c  |  176 
 drivers/media/rc/img-ir/img-ir-hw.c| 1053 
 drivers/media/rc/img-ir/img-ir-hw.h|  269 +
 drivers/media/rc/img-ir/img-ir-jvc.c   |   92 ++
 drivers/media/rc/img-ir/img-ir-nec.c   |  148 +++
 drivers/media/rc/img-ir/img-ir-raw.c   |  151 +++
 drivers/media/rc/img-ir/img-ir-raw.h   |   60 ++
 drivers/media/rc/img-ir/img-ir-sanyo.c |  122 +++
 drivers/media/rc/img-ir/img-ir-sharp.c |   99 ++
 drivers/media/rc/img-ir/img-ir-sony.c  |  145 +++
 drivers/media/rc/img-ir/img-ir.h   |  166 +++
 16 files changed, 2590 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/img-ir-rev1.txt
 create mode 100644 drivers/media/rc/img-ir/Kconfig
 create mode 100644 drivers/media/rc/img-ir/Makefile
 create mode 100644 drivers/media/rc/img-ir/img-ir-core.c
 create mode 100644 drivers/media/rc/img-ir/img-ir-hw.c
 create mode 100644 drivers/media/rc/img-ir/img-ir-hw.h
 create mode 100644 drivers/media/rc/img-ir/img-ir-jvc.c
 create mode 100644 drivers/media/rc/img-ir/img-ir-nec.c
 create mode 100644 drivers/media/rc/img-ir/img-ir-raw.c
 create mode 100644 drivers/media/rc/img-ir/img-ir-raw.h
 create mode 100644 drivers/media/rc/img-ir/img-ir-sanyo.c
 create mode 100644 drivers/media/rc/img-ir/img-ir-sharp.c
 create mode 100644 drivers/media/rc/img-ir/img-ir-sony.c
 create mode 100644 drivers/media/rc/img-ir/img-ir.h

-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 01/10] dt: binding: add binding for ImgTec IR block

2014-02-28 Thread James Hogan
Add device tree binding for ImgTec Consumer Infrared block, specifically
major revision 1 of the hardware.

Signed-off-by: James Hogan james.ho...@imgtec.com
Acked-by: Rob Herring r...@kernel.org
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: linux-media@vger.kernel.org
Cc: Pawel Moll pawel.m...@arm.com
Cc: Mark Rutland mark.rutl...@arm.com
Cc: Ian Campbell ijc+devicet...@hellion.org.uk
Cc: Kumar Gala ga...@codeaurora.org
Cc: devicet...@vger.kernel.org
Cc: Rob Landley r...@landley.net
Cc: linux-...@vger.kernel.org
Cc: Tomasz Figa tomasz.f...@gmail.com
---
v3:
- Rename compatible string to img,ir-rev1 (Rob Herring).
- Specify ordering of clocks explicitly (Rob Herring).

v2:
- Future proof compatible string from img,ir to img,ir1, where the 1
  corresponds to the major revision number of the hardware (Tomasz
  Figa).
- Added clock-names property and three specific clock names described in
  the manual, only one of which is used by the current driver (Tomasz
  Figa).
---
 .../devicetree/bindings/media/img-ir-rev1.txt  | 34 ++
 1 file changed, 34 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/img-ir-rev1.txt

diff --git a/Documentation/devicetree/bindings/media/img-ir-rev1.txt 
b/Documentation/devicetree/bindings/media/img-ir-rev1.txt
new file mode 100644
index 000..5434ce6
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/img-ir-rev1.txt
@@ -0,0 +1,34 @@
+* ImgTec Infrared (IR) decoder version 1
+
+This binding is for Imagination Technologies' Infrared decoder block,
+specifically major revision 1.
+
+Required properties:
+- compatible:  Should be img,ir-rev1
+- reg: Physical base address of the controller and length of
+   memory mapped region.
+- interrupts:  The interrupt specifier to the cpu.
+
+Optional properties:
+- clocks:  List of clock specifiers as described in standard
+   clock bindings.
+   Up to 3 clocks may be specified in the following order:
+   1st:Core clock (defaults to 32.768KHz if omitted).
+   2nd:System side (fast) clock.
+   3rd:Power modulation clock.
+- clock-names: List of clock names corresponding to the clocks
+   specified in the clocks property.
+   Accepted clock names are:
+   core: Core clock.
+   sys:  System clock.
+   mod:  Power modulation clock.
+
+Example:
+
+   ir@02006200 {
+   compatible = img,ir-rev1;
+   reg = 0x02006200 0x100;
+   interrupts = 29 4;
+   clocks = clk_32khz;
+   clock-names =  core;
+   };
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 02/10] rc: img-ir: add base driver

2014-02-28 Thread James Hogan
Add base driver for the ImgTec Infrared decoder block. The driver is
split into separate components for raw (software) decode and hardware
decoder which are in following commits.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: linux-media@vger.kernel.org
Cc: Grant Likely grant.lik...@linaro.org
Cc: Rob Herring robh...@kernel.org
Cc: devicet...@vger.kernel.org
---
v3:
- Use new compatible string img,ir-rev1.

v2:
- Use new DT binding, with a different compatibility string and get core
  clock by name.
- Remove next pointer from struct img_ir_priv. This is related to the
  removal of dynamic registration/unregistration of protocol decode
  timings from later patches.
- Add io.h include to img-ir.h.
---
 drivers/media/rc/img-ir/img-ir-core.c | 176 ++
 drivers/media/rc/img-ir/img-ir.h  | 166 
 2 files changed, 342 insertions(+)
 create mode 100644 drivers/media/rc/img-ir/img-ir-core.c
 create mode 100644 drivers/media/rc/img-ir/img-ir.h

diff --git a/drivers/media/rc/img-ir/img-ir-core.c 
b/drivers/media/rc/img-ir/img-ir-core.c
new file mode 100644
index 000..6b78348
--- /dev/null
+++ b/drivers/media/rc/img-ir/img-ir-core.c
@@ -0,0 +1,176 @@
+/*
+ * ImgTec IR Decoder found in PowerDown Controller.
+ *
+ * Copyright 2010-2014 Imagination Technologies Ltd.
+ *
+ * This contains core img-ir code for setting up the driver. The two interfaces
+ * (raw and hardware decode) are handled separately.
+ */
+
+#include linux/clk.h
+#include linux/init.h
+#include linux/interrupt.h
+#include linux/io.h
+#include linux/module.h
+#include linux/platform_device.h
+#include linux/slab.h
+#include linux/spinlock.h
+#include img-ir.h
+
+static irqreturn_t img_ir_isr(int irq, void *dev_id)
+{
+   struct img_ir_priv *priv = dev_id;
+   u32 irq_status;
+
+   spin_lock(priv-lock);
+   /* we have to clear irqs before reading */
+   irq_status = img_ir_read(priv, IMG_IR_IRQ_STATUS);
+   img_ir_write(priv, IMG_IR_IRQ_CLEAR, irq_status);
+
+   /* don't handle valid data irqs if we're only interested in matches */
+   irq_status = img_ir_read(priv, IMG_IR_IRQ_ENABLE);
+
+   /* hand off edge interrupts to raw decode handler */
+   if (irq_status  IMG_IR_IRQ_EDGE  img_ir_raw_enabled(priv-raw))
+   img_ir_isr_raw(priv, irq_status);
+
+   /* hand off hardware match interrupts to hardware decode handler */
+   if (irq_status  (IMG_IR_IRQ_DATA_MATCH |
+ IMG_IR_IRQ_DATA_VALID |
+ IMG_IR_IRQ_DATA2_VALID) 
+   img_ir_hw_enabled(priv-hw))
+   img_ir_isr_hw(priv, irq_status);
+
+   spin_unlock(priv-lock);
+   return IRQ_HANDLED;
+}
+
+static void img_ir_setup(struct img_ir_priv *priv)
+{
+   /* start off with interrupts disabled */
+   img_ir_write(priv, IMG_IR_IRQ_ENABLE, 0);
+
+   img_ir_setup_raw(priv);
+   img_ir_setup_hw(priv);
+
+   if (!IS_ERR(priv-clk))
+   clk_prepare_enable(priv-clk);
+}
+
+static void img_ir_ident(struct img_ir_priv *priv)
+{
+   u32 core_rev = img_ir_read(priv, IMG_IR_CORE_REV);
+
+   dev_info(priv-dev,
+IMG IR Decoder (%d.%d.%d.%d) probed successfully\n,
+(core_rev  IMG_IR_DESIGNER)  IMG_IR_DESIGNER_SHIFT,
+(core_rev  IMG_IR_MAJOR_REV)  IMG_IR_MAJOR_REV_SHIFT,
+(core_rev  IMG_IR_MINOR_REV)  IMG_IR_MINOR_REV_SHIFT,
+(core_rev  IMG_IR_MAINT_REV)  IMG_IR_MAINT_REV_SHIFT);
+   dev_info(priv-dev, Modes:%s%s\n,
+img_ir_hw_enabled(priv-hw) ?  hardware : ,
+img_ir_raw_enabled(priv-raw) ?  raw : );
+}
+
+static int img_ir_probe(struct platform_device *pdev)
+{
+   struct img_ir_priv *priv;
+   struct resource *res_regs;
+   int irq, error, error2;
+
+   /* Get resources from platform device */
+   irq = platform_get_irq(pdev, 0);
+   if (irq  0) {
+   dev_err(pdev-dev, cannot find IRQ resource\n);
+   return irq;
+   }
+
+   /* Private driver data */
+   priv = devm_kzalloc(pdev-dev, sizeof(*priv), GFP_KERNEL);
+   if (!priv) {
+   dev_err(pdev-dev, cannot allocate device data\n);
+   return -ENOMEM;
+   }
+   platform_set_drvdata(pdev, priv);
+   priv-dev = pdev-dev;
+   spin_lock_init(priv-lock);
+
+   /* Ioremap the registers */
+   res_regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   priv-reg_base = devm_ioremap_resource(pdev-dev, res_regs);
+   if (IS_ERR(priv-reg_base))
+   return PTR_ERR(priv-reg_base);
+
+   /* Get core clock */
+   priv-clk = devm_clk_get(pdev-dev, core);
+   if (IS_ERR(priv-clk))
+   dev_warn(pdev-dev, cannot get core clock resource\n);
+   /*
+* The driver doesn't need to know about the system (sys) or power

[PATCH v4 05/10] rc: img-ir: add to build

2014-02-28 Thread James Hogan
Add ImgTec IR decoder driver to the build system.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: linux-media@vger.kernel.org
---
 drivers/media/rc/Kconfig |  2 ++
 drivers/media/rc/Makefile|  1 +
 drivers/media/rc/img-ir/Kconfig  | 26 ++
 drivers/media/rc/img-ir/Makefile |  6 ++
 4 files changed, 35 insertions(+)
 create mode 100644 drivers/media/rc/img-ir/Kconfig
 create mode 100644 drivers/media/rc/img-ir/Makefile

diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 3b25887..8fbd377 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -309,6 +309,8 @@ config IR_RX51
   The driver uses omap DM timers for generating the carrier
   wave and pulses.
 
+source drivers/media/rc/img-ir/Kconfig
+
 config RC_LOOPBACK
tristate Remote Control Loopback Driver
depends on RC_CORE
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index 36dafed..f8b54ff 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -32,3 +32,4 @@ obj-$(CONFIG_IR_GPIO_CIR) += gpio-ir-recv.o
 obj-$(CONFIG_IR_IGUANA) += iguanair.o
 obj-$(CONFIG_IR_TTUSBIR) += ttusbir.o
 obj-$(CONFIG_RC_ST) += st_rc.o
+obj-$(CONFIG_IR_IMG) += img-ir/
diff --git a/drivers/media/rc/img-ir/Kconfig b/drivers/media/rc/img-ir/Kconfig
new file mode 100644
index 000..60eaba6
--- /dev/null
+++ b/drivers/media/rc/img-ir/Kconfig
@@ -0,0 +1,26 @@
+config IR_IMG
+   tristate ImgTec IR Decoder
+   depends on RC_CORE
+   select IR_IMG_HW if !IR_IMG_RAW
+   help
+  Say Y or M here if you want to use the ImgTec infrared decoder
+  functionality found in SoCs such as TZ1090.
+
+config IR_IMG_RAW
+   bool Raw decoder
+   depends on IR_IMG
+   help
+  Say Y here to enable the raw mode driver which passes raw IR signal
+  changes to the IR raw decoders for software decoding. This is much
+  less reliable (due to lack of timestamps) and consumes more
+  processing power than using hardware decode, but can be useful for
+  testing, debug, and to make more protocols available.
+
+config IR_IMG_HW
+   bool Hardware decoder
+   depends on IR_IMG
+   help
+  Say Y here to enable the hardware decode driver which decodes the IR
+  signals in hardware. This is more reliable, consumes less processing
+  power since only a single interrupt is received for each scancode,
+  and allows an IR scancode to be used as a wake event.
diff --git a/drivers/media/rc/img-ir/Makefile b/drivers/media/rc/img-ir/Makefile
new file mode 100644
index 000..4ef86ed
--- /dev/null
+++ b/drivers/media/rc/img-ir/Makefile
@@ -0,0 +1,6 @@
+img-ir-y   := img-ir-core.o
+img-ir-$(CONFIG_IR_IMG_RAW)+= img-ir-raw.o
+img-ir-$(CONFIG_IR_IMG_HW) += img-ir-hw.o
+img-ir-objs:= $(img-ir-y)
+
+obj-$(CONFIG_IR_IMG)   += img-ir.o
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 07/10] rc: img-ir: add JVC decoder module

2014-02-28 Thread James Hogan
Add an img-ir module for decoding the JVC infrared protocol.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: linux-media@vger.kernel.org
---
v2:
- Update to new scancode interface (32-bit NEC).
- Update to new filtering interface (generic struct rc_scancode_filter).
- Remove modularity and dynamic registration/unregistration, adding JVC
  directly to the list of decoders in img-ir-hw.c.
---
 drivers/media/rc/img-ir/Kconfig  |  7 +++
 drivers/media/rc/img-ir/Makefile |  1 +
 drivers/media/rc/img-ir/img-ir-hw.c  |  4 ++
 drivers/media/rc/img-ir/img-ir-jvc.c | 92 
 4 files changed, 104 insertions(+)
 create mode 100644 drivers/media/rc/img-ir/img-ir-jvc.c

diff --git a/drivers/media/rc/img-ir/Kconfig b/drivers/media/rc/img-ir/Kconfig
index 28498a2..96006fbf 100644
--- a/drivers/media/rc/img-ir/Kconfig
+++ b/drivers/media/rc/img-ir/Kconfig
@@ -31,3 +31,10 @@ config IR_IMG_NEC
help
   Say Y here to enable support for the NEC, extended NEC, and 32-bit
   NEC protocols in the ImgTec infrared decoder block.
+
+config IR_IMG_JVC
+   bool JVC protocol support
+   depends on IR_IMG_HW
+   help
+  Say Y here to enable support for the JVC protocol in the ImgTec
+  infrared decoder block.
diff --git a/drivers/media/rc/img-ir/Makefile b/drivers/media/rc/img-ir/Makefile
index c409197..c5f8f06 100644
--- a/drivers/media/rc/img-ir/Makefile
+++ b/drivers/media/rc/img-ir/Makefile
@@ -2,6 +2,7 @@ img-ir-y:= img-ir-core.o
 img-ir-$(CONFIG_IR_IMG_RAW)+= img-ir-raw.o
 img-ir-$(CONFIG_IR_IMG_HW) += img-ir-hw.o
 img-ir-$(CONFIG_IR_IMG_NEC)+= img-ir-nec.o
+img-ir-$(CONFIG_IR_IMG_JVC)+= img-ir-jvc.o
 img-ir-objs:= $(img-ir-y)
 
 obj-$(CONFIG_IR_IMG)   += img-ir.o
diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
b/drivers/media/rc/img-ir/img-ir-hw.c
index 139f2c7..81c50e3 100644
--- a/drivers/media/rc/img-ir/img-ir-hw.c
+++ b/drivers/media/rc/img-ir/img-ir-hw.c
@@ -21,12 +21,16 @@
 static DEFINE_SPINLOCK(img_ir_decoders_lock);
 
 extern struct img_ir_decoder img_ir_nec;
+extern struct img_ir_decoder img_ir_jvc;
 
 static bool img_ir_decoders_preprocessed;
 static struct img_ir_decoder *img_ir_decoders[] = {
 #ifdef CONFIG_IR_IMG_NEC
img_ir_nec,
 #endif
+#ifdef CONFIG_IR_IMG_JVC
+   img_ir_jvc,
+#endif
NULL
 };
 
diff --git a/drivers/media/rc/img-ir/img-ir-jvc.c 
b/drivers/media/rc/img-ir/img-ir-jvc.c
new file mode 100644
index 000..ae55867
--- /dev/null
+++ b/drivers/media/rc/img-ir/img-ir-jvc.c
@@ -0,0 +1,92 @@
+/*
+ * ImgTec IR Decoder setup for JVC protocol.
+ *
+ * Copyright 2012-2014 Imagination Technologies Ltd.
+ */
+
+#include img-ir-hw.h
+
+/* Convert JVC data to a scancode */
+static int img_ir_jvc_scancode(int len, u64 raw, int *scancode, u64 protocols)
+{
+   unsigned int cust, data;
+
+   if (len != 16)
+   return -EINVAL;
+
+   cust = (raw  0)  0xff;
+   data = (raw  8)  0xff;
+
+   *scancode = cust  8 | data;
+   return IMG_IR_SCANCODE;
+}
+
+/* Convert JVC scancode to JVC data filter */
+static int img_ir_jvc_filter(const struct rc_scancode_filter *in,
+struct img_ir_filter *out, u64 protocols)
+{
+   unsigned int cust, data;
+   unsigned int cust_m, data_m;
+
+   cust   = (in-data  8)  0xff;
+   cust_m = (in-mask  8)  0xff;
+   data   = (in-data  0)  0xff;
+   data_m = (in-mask  0)  0xff;
+
+   out-data = cust   | data  8;
+   out-mask = cust_m | data_m  8;
+
+   return 0;
+}
+
+/*
+ * JVC decoder
+ * See also http://www.sbprojects.com/knowledge/ir/jvc.php
+ *  http://support.jvc.com/consumer/support/documents/RemoteCodes.pdf
+ */
+struct img_ir_decoder img_ir_jvc = {
+   .type = RC_BIT_JVC,
+   .control = {
+   .decoden = 1,
+   .code_type = IMG_IR_CODETYPE_PULSEDIST,
+   .decodend2 = 1,
+   },
+   /* main timings */
+   .unit = 527500, /* 527.5 us */
+   .timings = {
+   /* leader symbol */
+   .ldr = {
+   .pulse = { 16   /* 8.44 ms */ },
+   .space = { 8/* 4.22 ms */ },
+   },
+   /* 0 symbol */
+   .s00 = {
+   .pulse = { 1/* 527.5 us +-60 us */ },
+   .space = { 1/* 527.5 us */ },
+   },
+   /* 1 symbol */
+   .s01 = {
+   .pulse = { 1/* 527.5 us +-60 us */ },
+   .space = { 3/* 1.5825 ms +-40 us */ },
+   },
+   /* 0 symbol (no leader) */
+   .s00 = {
+   .pulse = { 1/* 527.5 us +-60 us */ },
+   .space = { 1/* 527.5 us */ },
+   },
+   /* 1 symbol (no leader

[PATCH v4 08/10] rc: img-ir: add Sony decoder module

2014-02-28 Thread James Hogan
Add an img-ir module for decoding the Sony infrared protocol.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: linux-media@vger.kernel.org
---
v2:
- Update to new scancode interface (32-bit NEC).
- Update to new filtering interface (generic struct rc_scancode_filter).
- Remove modularity and dynamic registration/unregistration, adding Sony
  directly to the list of decoders in img-ir-hw.c.
---
 drivers/media/rc/img-ir/Kconfig   |   7 ++
 drivers/media/rc/img-ir/Makefile  |   1 +
 drivers/media/rc/img-ir/img-ir-hw.c   |   4 +
 drivers/media/rc/img-ir/img-ir-sony.c | 145 ++
 4 files changed, 157 insertions(+)
 create mode 100644 drivers/media/rc/img-ir/img-ir-sony.c

diff --git a/drivers/media/rc/img-ir/Kconfig b/drivers/media/rc/img-ir/Kconfig
index 96006fbf..ab36577 100644
--- a/drivers/media/rc/img-ir/Kconfig
+++ b/drivers/media/rc/img-ir/Kconfig
@@ -38,3 +38,10 @@ config IR_IMG_JVC
help
   Say Y here to enable support for the JVC protocol in the ImgTec
   infrared decoder block.
+
+config IR_IMG_SONY
+   bool Sony protocol support
+   depends on IR_IMG_HW
+   help
+  Say Y here to enable support for the Sony protocol in the ImgTec
+  infrared decoder block.
diff --git a/drivers/media/rc/img-ir/Makefile b/drivers/media/rc/img-ir/Makefile
index c5f8f06..978c0c6 100644
--- a/drivers/media/rc/img-ir/Makefile
+++ b/drivers/media/rc/img-ir/Makefile
@@ -3,6 +3,7 @@ img-ir-$(CONFIG_IR_IMG_RAW) += img-ir-raw.o
 img-ir-$(CONFIG_IR_IMG_HW) += img-ir-hw.o
 img-ir-$(CONFIG_IR_IMG_NEC)+= img-ir-nec.o
 img-ir-$(CONFIG_IR_IMG_JVC)+= img-ir-jvc.o
+img-ir-$(CONFIG_IR_IMG_SONY)   += img-ir-sony.o
 img-ir-objs:= $(img-ir-y)
 
 obj-$(CONFIG_IR_IMG)   += img-ir.o
diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
b/drivers/media/rc/img-ir/img-ir-hw.c
index 81c50e3..0d4f921 100644
--- a/drivers/media/rc/img-ir/img-ir-hw.c
+++ b/drivers/media/rc/img-ir/img-ir-hw.c
@@ -22,6 +22,7 @@ static DEFINE_SPINLOCK(img_ir_decoders_lock);
 
 extern struct img_ir_decoder img_ir_nec;
 extern struct img_ir_decoder img_ir_jvc;
+extern struct img_ir_decoder img_ir_sony;
 
 static bool img_ir_decoders_preprocessed;
 static struct img_ir_decoder *img_ir_decoders[] = {
@@ -31,6 +32,9 @@ static struct img_ir_decoder *img_ir_decoders[] = {
 #ifdef CONFIG_IR_IMG_JVC
img_ir_jvc,
 #endif
+#ifdef CONFIG_IR_IMG_SONY
+   img_ir_sony,
+#endif
NULL
 };
 
diff --git a/drivers/media/rc/img-ir/img-ir-sony.c 
b/drivers/media/rc/img-ir/img-ir-sony.c
new file mode 100644
index 000..993409a
--- /dev/null
+++ b/drivers/media/rc/img-ir/img-ir-sony.c
@@ -0,0 +1,145 @@
+/*
+ * ImgTec IR Decoder setup for Sony (SIRC) protocol.
+ *
+ * Copyright 2012-2014 Imagination Technologies Ltd.
+ */
+
+#include img-ir-hw.h
+
+/* Convert Sony data to a scancode */
+static int img_ir_sony_scancode(int len, u64 raw, int *scancode, u64 protocols)
+{
+   unsigned int dev, subdev, func;
+
+   switch (len) {
+   case 12:
+   if (!(protocols  RC_BIT_SONY12))
+   return -EINVAL;
+   func   = raw  0x7f;/* first 7 bits */
+   raw= 7;
+   dev= raw  0x1f;/* next 5 bits */
+   subdev = 0;
+   break;
+   case 15:
+   if (!(protocols  RC_BIT_SONY15))
+   return -EINVAL;
+   func   = raw  0x7f;/* first 7 bits */
+   raw= 7;
+   dev= raw  0xff;/* next 8 bits */
+   subdev = 0;
+   break;
+   case 20:
+   if (!(protocols  RC_BIT_SONY20))
+   return -EINVAL;
+   func   = raw  0x7f;/* first 7 bits */
+   raw= 7;
+   dev= raw  0x1f;/* next 5 bits */
+   raw= 5;
+   subdev = raw  0xff;/* next 8 bits */
+   break;
+   default:
+   return -EINVAL;
+   }
+   *scancode = dev  16 | subdev  8 | func;
+   return IMG_IR_SCANCODE;
+}
+
+/* Convert NEC scancode to NEC data filter */
+static int img_ir_sony_filter(const struct rc_scancode_filter *in,
+ struct img_ir_filter *out, u64 protocols)
+{
+   unsigned int dev, subdev, func;
+   unsigned int dev_m, subdev_m, func_m;
+   unsigned int len = 0;
+
+   dev  = (in-data  16)  0xff;
+   dev_m= (in-mask  16)  0xff;
+   subdev   = (in-data  8)   0xff;
+   subdev_m = (in-mask  8)   0xff;
+   func = (in-data  0)   0x7f;
+   func_m   = (in-mask  0)   0x7f;
+
+   if (subdev  subdev_m) {
+   /* can't encode subdev and higher device bits */
+   if (dev  dev_m  0xe0)
+   return -EINVAL;
+   /* subdevice (extended) bits only in 20 bit encoding

[PATCH v4 09/10] rc: img-ir: add Sharp decoder module

2014-02-28 Thread James Hogan
Add an img-ir module for decoding the Sharp infrared protocol.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: linux-media@vger.kernel.org
---
v2:
- Update to new scancode interface (32-bit NEC).
- Update to new filtering interface (generic struct rc_scancode_filter).
- Remove modularity and dynamic registration/unregistration, adding
  Sharp directly to the list of decoders in img-ir-hw.c.
- Fix typo in logic 1 pulse width comment.
- Set tolerance to 20%, which seemed to be needed for the cases I have.
---
 drivers/media/rc/img-ir/Kconfig|  7 +++
 drivers/media/rc/img-ir/Makefile   |  1 +
 drivers/media/rc/img-ir/img-ir-hw.c|  4 ++
 drivers/media/rc/img-ir/img-ir-sharp.c | 99 ++
 4 files changed, 111 insertions(+)
 create mode 100644 drivers/media/rc/img-ir/img-ir-sharp.c

diff --git a/drivers/media/rc/img-ir/Kconfig b/drivers/media/rc/img-ir/Kconfig
index ab36577..48627f9 100644
--- a/drivers/media/rc/img-ir/Kconfig
+++ b/drivers/media/rc/img-ir/Kconfig
@@ -45,3 +45,10 @@ config IR_IMG_SONY
help
   Say Y here to enable support for the Sony protocol in the ImgTec
   infrared decoder block.
+
+config IR_IMG_SHARP
+   bool Sharp protocol support
+   depends on IR_IMG_HW
+   help
+  Say Y here to enable support for the Sharp protocol in the ImgTec
+  infrared decoder block.
diff --git a/drivers/media/rc/img-ir/Makefile b/drivers/media/rc/img-ir/Makefile
index 978c0c6..792a3c4 100644
--- a/drivers/media/rc/img-ir/Makefile
+++ b/drivers/media/rc/img-ir/Makefile
@@ -4,6 +4,7 @@ img-ir-$(CONFIG_IR_IMG_HW)  += img-ir-hw.o
 img-ir-$(CONFIG_IR_IMG_NEC)+= img-ir-nec.o
 img-ir-$(CONFIG_IR_IMG_JVC)+= img-ir-jvc.o
 img-ir-$(CONFIG_IR_IMG_SONY)   += img-ir-sony.o
+img-ir-$(CONFIG_IR_IMG_SHARP)  += img-ir-sharp.o
 img-ir-objs:= $(img-ir-y)
 
 obj-$(CONFIG_IR_IMG)   += img-ir.o
diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
b/drivers/media/rc/img-ir/img-ir-hw.c
index 0d4f921..9931dfa 100644
--- a/drivers/media/rc/img-ir/img-ir-hw.c
+++ b/drivers/media/rc/img-ir/img-ir-hw.c
@@ -23,6 +23,7 @@ static DEFINE_SPINLOCK(img_ir_decoders_lock);
 extern struct img_ir_decoder img_ir_nec;
 extern struct img_ir_decoder img_ir_jvc;
 extern struct img_ir_decoder img_ir_sony;
+extern struct img_ir_decoder img_ir_sharp;
 
 static bool img_ir_decoders_preprocessed;
 static struct img_ir_decoder *img_ir_decoders[] = {
@@ -35,6 +36,9 @@ static struct img_ir_decoder *img_ir_decoders[] = {
 #ifdef CONFIG_IR_IMG_SONY
img_ir_sony,
 #endif
+#ifdef CONFIG_IR_IMG_SHARP
+   img_ir_sharp,
+#endif
NULL
 };
 
diff --git a/drivers/media/rc/img-ir/img-ir-sharp.c 
b/drivers/media/rc/img-ir/img-ir-sharp.c
new file mode 100644
index 000..3397cc5
--- /dev/null
+++ b/drivers/media/rc/img-ir/img-ir-sharp.c
@@ -0,0 +1,99 @@
+/*
+ * ImgTec IR Decoder setup for Sharp protocol.
+ *
+ * Copyright 2012-2014 Imagination Technologies Ltd.
+ */
+
+#include img-ir-hw.h
+
+/* Convert Sharp data to a scancode */
+static int img_ir_sharp_scancode(int len, u64 raw, int *scancode, u64 
protocols)
+{
+   unsigned int addr, cmd, exp, chk;
+
+   if (len != 15)
+   return -EINVAL;
+
+   addr = (raw0)  0x1f;
+   cmd  = (raw5)  0xff;
+   exp  = (raw   13)   0x1;
+   chk  = (raw   14)   0x1;
+
+   /* validate data */
+   if (!exp)
+   return -EINVAL;
+   if (chk)
+   /* probably the second half of the message */
+   return -EINVAL;
+
+   *scancode = addr  8 | cmd;
+   return IMG_IR_SCANCODE;
+}
+
+/* Convert Sharp scancode to Sharp data filter */
+static int img_ir_sharp_filter(const struct rc_scancode_filter *in,
+  struct img_ir_filter *out, u64 protocols)
+{
+   unsigned int addr, cmd, exp = 0, chk = 0;
+   unsigned int addr_m, cmd_m, exp_m = 0, chk_m = 0;
+
+   addr   = (in-data  8)  0x1f;
+   addr_m = (in-mask  8)  0x1f;
+   cmd= (in-data  0)  0xff;
+   cmd_m  = (in-mask  0)  0xff;
+   if (cmd_m) {
+   /* if filtering commands, we can only match the first part */
+   exp   = 1;
+   exp_m = 1;
+   chk   = 0;
+   chk_m = 1;
+   }
+
+   out-data = addr|
+   cmd 5 |
+   exp13 |
+   chk14;
+   out-mask = addr_m  |
+   cmd_m   5 |
+   exp_m  13 |
+   chk_m  14;
+
+   return 0;
+}
+
+/*
+ * Sharp decoder
+ * See also http://www.sbprojects.com/knowledge/ir/sharp.php
+ */
+struct img_ir_decoder img_ir_sharp = {
+   .type = RC_BIT_SHARP,
+   .control = {
+   .decoden = 0,
+   .decodend2 = 1,
+   .code_type = IMG_IR_CODETYPE_PULSEDIST,
+   .d1validsel = 1

[PATCH v4 03/10] rc: img-ir: add raw driver

2014-02-28 Thread James Hogan
Add raw IR remote control input driver for the ImgTec Infrared decoder
block's raw edge interrupts. Generic software protocol decoders are used
to allow multiple protocols to be supported at a time, including those
not supported by the hardware decoder.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: linux-media@vger.kernel.org
---
v2:
- Echo the last sample after 150ms if no edges have been detected. This
  allows the soft decoder state machines to recognise the final space
  when no repeat code is received.
- Use spin_lock_irq() instead of spin_lock_irqsave() in various bits of
  code that aren't accessible from hard interrupt context.
- Avoid removal race by checking for RC device in ISR.
---
 drivers/media/rc/img-ir/img-ir-raw.c | 151 +++
 drivers/media/rc/img-ir/img-ir-raw.h |  60 ++
 2 files changed, 211 insertions(+)
 create mode 100644 drivers/media/rc/img-ir/img-ir-raw.c
 create mode 100644 drivers/media/rc/img-ir/img-ir-raw.h

diff --git a/drivers/media/rc/img-ir/img-ir-raw.c 
b/drivers/media/rc/img-ir/img-ir-raw.c
new file mode 100644
index 000..cfb01d9
--- /dev/null
+++ b/drivers/media/rc/img-ir/img-ir-raw.c
@@ -0,0 +1,151 @@
+/*
+ * ImgTec IR Raw Decoder found in PowerDown Controller.
+ *
+ * Copyright 2010-2014 Imagination Technologies Ltd.
+ *
+ * This ties into the input subsystem using the RC-core in raw mode. Raw IR
+ * signal edges are reported and decoded by generic software decoders.
+ */
+
+#include linux/spinlock.h
+#include media/rc-core.h
+#include img-ir.h
+
+#define ECHO_TIMEOUT_MS 150/* ms between echos */
+
+/* must be called with priv-lock held */
+static void img_ir_refresh_raw(struct img_ir_priv *priv, u32 irq_status)
+{
+   struct img_ir_priv_raw *raw = priv-raw;
+   struct rc_dev *rc_dev = priv-raw.rdev;
+   int multiple;
+   u32 ir_status;
+
+   /* find whether both rise and fall was detected */
+   multiple = ((irq_status  IMG_IR_IRQ_EDGE) == IMG_IR_IRQ_EDGE);
+   /*
+* If so, we need to see if the level has actually changed.
+* If it's just noise that we didn't have time to process,
+* there's no point reporting it.
+*/
+   ir_status = img_ir_read(priv, IMG_IR_STATUS)  IMG_IR_IRRXD;
+   if (multiple  ir_status == raw-last_status)
+   return;
+   raw-last_status = ir_status;
+
+   /* report the edge to the IR raw decoders */
+   if (ir_status) /* low */
+   ir_raw_event_store_edge(rc_dev, IR_SPACE);
+   else /* high */
+   ir_raw_event_store_edge(rc_dev, IR_PULSE);
+   ir_raw_event_handle(rc_dev);
+}
+
+/* called with priv-lock held */
+void img_ir_isr_raw(struct img_ir_priv *priv, u32 irq_status)
+{
+   struct img_ir_priv_raw *raw = priv-raw;
+
+   /* check not removing */
+   if (!raw-rdev)
+   return;
+
+   img_ir_refresh_raw(priv, irq_status);
+
+   /* start / push back the echo timer */
+   mod_timer(raw-timer, jiffies + msecs_to_jiffies(ECHO_TIMEOUT_MS));
+}
+
+/*
+ * Echo timer callback function.
+ * The raw decoders expect to get a final sample even if there are no edges, in
+ * order to be assured of the final space. If there are no edges for a certain
+ * time we use this timer to emit a final sample to satisfy them.
+ */
+static void img_ir_echo_timer(unsigned long arg)
+{
+   struct img_ir_priv *priv = (struct img_ir_priv *)arg;
+
+   spin_lock_irq(priv-lock);
+
+   /* check not removing */
+   if (priv-raw.rdev)
+   /*
+* It's safe to pass irq_status=0 since it's only used to check
+* for double edges.
+*/
+   img_ir_refresh_raw(priv, 0);
+
+   spin_unlock_irq(priv-lock);
+}
+
+void img_ir_setup_raw(struct img_ir_priv *priv)
+{
+   u32 irq_en;
+
+   if (!priv-raw.rdev)
+   return;
+
+   /* clear and enable edge interrupts */
+   spin_lock_irq(priv-lock);
+   irq_en = img_ir_read(priv, IMG_IR_IRQ_ENABLE);
+   irq_en |= IMG_IR_IRQ_EDGE;
+   img_ir_write(priv, IMG_IR_IRQ_CLEAR, IMG_IR_IRQ_EDGE);
+   img_ir_write(priv, IMG_IR_IRQ_ENABLE, irq_en);
+   spin_unlock_irq(priv-lock);
+}
+
+int img_ir_probe_raw(struct img_ir_priv *priv)
+{
+   struct img_ir_priv_raw *raw = priv-raw;
+   struct rc_dev *rdev;
+   int error;
+
+   /* Set up the echo timer */
+   setup_timer(raw-timer, img_ir_echo_timer, (unsigned long)priv);
+
+   /* Allocate raw decoder */
+   raw-rdev = rdev = rc_allocate_device();
+   if (!rdev) {
+   dev_err(priv-dev, cannot allocate raw input device\n);
+   return -ENOMEM;
+   }
+   rdev-priv = priv;
+   rdev-map_name = RC_MAP_EMPTY;
+   rdev-input_name = IMG Infrared Decoder Raw;
+   rdev-driver_type = RC_DRIVER_IR_RAW;
+
+   /* Register raw decoder */
+   error

[PATCH v4 06/10] rc: img-ir: add NEC decoder module

2014-02-28 Thread James Hogan
Add an img-ir module for decoding the NEC and extended NEC infrared
protocols.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: linux-media@vger.kernel.org
---
v2:
- Update scancode and filter callbacks to handle 32-bit NEC as used by
  Apple and TiVo remotes (the new 32-bit NEC scancode format is used,
  with the correct bit orientation).
- Update to new scancode interface so that 32-bit NEC scancodes can be
  returned reliably.
- Update to new filtering interface (generic struct rc_scancode_filter).
- Make it possible to set the filter to extended NEC even when the high
  bits of the scancode value aren't set, by taking the mask into account
  too. My TV remote happens to use extended NEC with address 0x7f00,
  which unfortunately maps to scancodes 0x007f** which looks like normal
  NEC and couldn't previously be filtered.
- Remove modularity and dynamic registration/unregistration, adding NEC
  directly to the list of decoders in img-ir-hw.c.
---
 drivers/media/rc/img-ir/Kconfig  |   7 ++
 drivers/media/rc/img-ir/Makefile |   1 +
 drivers/media/rc/img-ir/img-ir-hw.c  |   5 ++
 drivers/media/rc/img-ir/img-ir-nec.c | 148 +++
 4 files changed, 161 insertions(+)
 create mode 100644 drivers/media/rc/img-ir/img-ir-nec.c

diff --git a/drivers/media/rc/img-ir/Kconfig b/drivers/media/rc/img-ir/Kconfig
index 60eaba6..28498a2 100644
--- a/drivers/media/rc/img-ir/Kconfig
+++ b/drivers/media/rc/img-ir/Kconfig
@@ -24,3 +24,10 @@ config IR_IMG_HW
   signals in hardware. This is more reliable, consumes less processing
   power since only a single interrupt is received for each scancode,
   and allows an IR scancode to be used as a wake event.
+
+config IR_IMG_NEC
+   bool NEC protocol support
+   depends on IR_IMG_HW
+   help
+  Say Y here to enable support for the NEC, extended NEC, and 32-bit
+  NEC protocols in the ImgTec infrared decoder block.
diff --git a/drivers/media/rc/img-ir/Makefile b/drivers/media/rc/img-ir/Makefile
index 4ef86ed..c409197 100644
--- a/drivers/media/rc/img-ir/Makefile
+++ b/drivers/media/rc/img-ir/Makefile
@@ -1,6 +1,7 @@
 img-ir-y   := img-ir-core.o
 img-ir-$(CONFIG_IR_IMG_RAW)+= img-ir-raw.o
 img-ir-$(CONFIG_IR_IMG_HW) += img-ir-hw.o
+img-ir-$(CONFIG_IR_IMG_NEC)+= img-ir-nec.o
 img-ir-objs:= $(img-ir-y)
 
 obj-$(CONFIG_IR_IMG)   += img-ir.o
diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
b/drivers/media/rc/img-ir/img-ir-hw.c
index 21c8bbc..139f2c7 100644
--- a/drivers/media/rc/img-ir/img-ir-hw.c
+++ b/drivers/media/rc/img-ir/img-ir-hw.c
@@ -20,8 +20,13 @@
 /* Decoders lock (only modified to preprocess them) */
 static DEFINE_SPINLOCK(img_ir_decoders_lock);
 
+extern struct img_ir_decoder img_ir_nec;
+
 static bool img_ir_decoders_preprocessed;
 static struct img_ir_decoder *img_ir_decoders[] = {
+#ifdef CONFIG_IR_IMG_NEC
+   img_ir_nec,
+#endif
NULL
 };
 
diff --git a/drivers/media/rc/img-ir/img-ir-nec.c 
b/drivers/media/rc/img-ir/img-ir-nec.c
new file mode 100644
index 000..e7a731b
--- /dev/null
+++ b/drivers/media/rc/img-ir/img-ir-nec.c
@@ -0,0 +1,148 @@
+/*
+ * ImgTec IR Decoder setup for NEC protocol.
+ *
+ * Copyright 2010-2014 Imagination Technologies Ltd.
+ */
+
+#include img-ir-hw.h
+
+/* Convert NEC data to a scancode */
+static int img_ir_nec_scancode(int len, u64 raw, int *scancode, u64 protocols)
+{
+   unsigned int addr, addr_inv, data, data_inv;
+   /* a repeat code has no data */
+   if (!len)
+   return IMG_IR_REPEATCODE;
+   if (len != 32)
+   return -EINVAL;
+   /* raw encoding: ddDDaaAA */
+   addr = (raw   0)  0xff;
+   addr_inv = (raw   8)  0xff;
+   data = (raw  16)  0xff;
+   data_inv = (raw  24)  0xff;
+   if ((data_inv ^ data) != 0xff) {
+   /* 32-bit NEC (used by Apple and TiVo remotes) */
+   /* scan encoding: aaAAddDD */
+   *scancode = addr_inv  24 |
+   addr  16 |
+   data_inv   8 |
+   data;
+   } else if ((addr_inv ^ addr) != 0xff) {
+   /* Extended NEC */
+   /* scan encoding: AAaaDD */
+   *scancode = addr  16 |
+   addr_inv   8 |
+   data;
+   } else {
+   /* Normal NEC */
+   /* scan encoding: AADD */
+   *scancode = addr  8 |
+   data;
+   }
+   return IMG_IR_SCANCODE;
+}
+
+/* Convert NEC scancode to NEC data filter */
+static int img_ir_nec_filter(const struct rc_scancode_filter *in,
+struct img_ir_filter *out, u64 protocols)
+{
+   unsigned int addr, addr_inv, data, data_inv;
+   unsigned int addr_m, addr_inv_m, data_m, data_inv_m;
+
+   data

[PATCH v4 10/10] rc: img-ir: add Sanyo decoder module

2014-02-28 Thread James Hogan
Add an img-ir module for decoding the Sanyo infrared protocol.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: linux-media@vger.kernel.org
---
v2:
- Update to new scancode interface (32-bit NEC).
- Update to new filtering interface (generic struct rc_scancode_filter).
- Remove modularity and dynamic registration/unregistration, adding
  Sanyo directly to the list of decoders in img-ir-hw.c.
---
 drivers/media/rc/img-ir/Kconfig|   7 ++
 drivers/media/rc/img-ir/Makefile   |   1 +
 drivers/media/rc/img-ir/img-ir-hw.c|   4 ++
 drivers/media/rc/img-ir/img-ir-sanyo.c | 122 +
 4 files changed, 134 insertions(+)
 create mode 100644 drivers/media/rc/img-ir/img-ir-sanyo.c

diff --git a/drivers/media/rc/img-ir/Kconfig b/drivers/media/rc/img-ir/Kconfig
index 48627f9..03ba9fc 100644
--- a/drivers/media/rc/img-ir/Kconfig
+++ b/drivers/media/rc/img-ir/Kconfig
@@ -52,3 +52,10 @@ config IR_IMG_SHARP
help
   Say Y here to enable support for the Sharp protocol in the ImgTec
   infrared decoder block.
+
+config IR_IMG_SANYO
+   bool Sanyo protocol support
+   depends on IR_IMG_HW
+   help
+  Say Y here to enable support for the Sanyo protocol (used by Sanyo,
+  Aiwa, Chinon remotes) in the ImgTec infrared decoder block.
diff --git a/drivers/media/rc/img-ir/Makefile b/drivers/media/rc/img-ir/Makefile
index 792a3c4..92a459d 100644
--- a/drivers/media/rc/img-ir/Makefile
+++ b/drivers/media/rc/img-ir/Makefile
@@ -5,6 +5,7 @@ img-ir-$(CONFIG_IR_IMG_NEC) += img-ir-nec.o
 img-ir-$(CONFIG_IR_IMG_JVC)+= img-ir-jvc.o
 img-ir-$(CONFIG_IR_IMG_SONY)   += img-ir-sony.o
 img-ir-$(CONFIG_IR_IMG_SHARP)  += img-ir-sharp.o
+img-ir-$(CONFIG_IR_IMG_SANYO)  += img-ir-sanyo.o
 img-ir-objs:= $(img-ir-y)
 
 obj-$(CONFIG_IR_IMG)   += img-ir.o
diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
b/drivers/media/rc/img-ir/img-ir-hw.c
index 9931dfa..cbbfd7d 100644
--- a/drivers/media/rc/img-ir/img-ir-hw.c
+++ b/drivers/media/rc/img-ir/img-ir-hw.c
@@ -24,6 +24,7 @@ extern struct img_ir_decoder img_ir_nec;
 extern struct img_ir_decoder img_ir_jvc;
 extern struct img_ir_decoder img_ir_sony;
 extern struct img_ir_decoder img_ir_sharp;
+extern struct img_ir_decoder img_ir_sanyo;
 
 static bool img_ir_decoders_preprocessed;
 static struct img_ir_decoder *img_ir_decoders[] = {
@@ -39,6 +40,9 @@ static struct img_ir_decoder *img_ir_decoders[] = {
 #ifdef CONFIG_IR_IMG_SHARP
img_ir_sharp,
 #endif
+#ifdef CONFIG_IR_IMG_SANYO
+   img_ir_sanyo,
+#endif
NULL
 };
 
diff --git a/drivers/media/rc/img-ir/img-ir-sanyo.c 
b/drivers/media/rc/img-ir/img-ir-sanyo.c
new file mode 100644
index 000..c2c763e
--- /dev/null
+++ b/drivers/media/rc/img-ir/img-ir-sanyo.c
@@ -0,0 +1,122 @@
+/*
+ * ImgTec IR Decoder setup for Sanyo protocol.
+ *
+ * Copyright 2012-2014 Imagination Technologies Ltd.
+ *
+ * From ir-sanyo-decoder.c:
+ *
+ * This protocol uses the NEC protocol timings. However, data is formatted as:
+ * 13 bits Custom Code
+ * 13 bits NOT(Custom Code)
+ * 8 bits Key data
+ * 8 bits NOT(Key data)
+ *
+ * According with LIRC, this protocol is used on Sanyo, Aiwa and Chinon
+ * Information for this protocol is available at the Sanyo LC7461 datasheet.
+ */
+
+#include img-ir-hw.h
+
+/* Convert Sanyo data to a scancode */
+static int img_ir_sanyo_scancode(int len, u64 raw, int *scancode, u64 
protocols)
+{
+   unsigned int addr, addr_inv, data, data_inv;
+   /* a repeat code has no data */
+   if (!len)
+   return IMG_IR_REPEATCODE;
+   if (len != 42)
+   return -EINVAL;
+   addr = (raw   0)  0x1fff;
+   addr_inv = (raw  13)  0x1fff;
+   data = (raw  26)  0xff;
+   data_inv = (raw  34)  0xff;
+   /* Validate data */
+   if ((data_inv ^ data) != 0xff)
+   return -EINVAL;
+   /* Validate address */
+   if ((addr_inv ^ addr) != 0x1fff)
+   return -EINVAL;
+
+   /* Normal Sanyo */
+   *scancode = addr  8 | data;
+   return IMG_IR_SCANCODE;
+}
+
+/* Convert Sanyo scancode to Sanyo data filter */
+static int img_ir_sanyo_filter(const struct rc_scancode_filter *in,
+  struct img_ir_filter *out, u64 protocols)
+{
+   unsigned int addr, addr_inv, data, data_inv;
+   unsigned int addr_m, data_m;
+
+   data = in-data  0xff;
+   data_m = in-mask  0xff;
+   data_inv = data ^ 0xff;
+
+   if (in-data  0xff70)
+   return -EINVAL;
+
+   addr   = (in-data  8)  0x1fff;
+   addr_m = (in-mask  8)  0x1fff;
+   addr_inv   = addr ^ 0x1fff;
+
+   out-data = (u64)data_inv  34 |
+   (u64)data  26 |
+addr_inv  13 |
+addr;
+   out-mask = (u64)data_m  34 |
+   (u64)data_m  26

[PATCH v4 04/10] rc: img-ir: add hardware decoder driver

2014-02-28 Thread James Hogan
Add remote control input driver for the ImgTec Infrared block hardware
decoder, which is set up with timings for a specific protocol and
supports mask/value filtering and wake events.

The hardware decoder timing values, raw data to scan code conversion
function and scan code filter to raw data filter conversion function
will be provided in separate files for each protocol which this part of
the driver can use. The new generic scan code filter interface is made
use of to reduce interrupts and control wake events.

Signed-off-by: James Hogan james.ho...@imgtec.com
Cc: Mauro Carvalho Chehab m.che...@samsung.com
Cc: linux-media@vger.kernel.org
---
v4:
- Rebase on RC filtering improvements patchset, and fix to use new
  allowed/enabled protocol abstractions.
- Depend on generic code to update normal filter on a protocol change.
- Minimal support for wakeup_protocols by setting allowed and enabled
  wakeup protocols to match the enabled normal protocol on a protocol
  change (but only if the protocol has filtering support in the driver).
  Supporting a different wakeup protocol to the normal protocol is left
  as a task for another day.

v2:
- Fix typo in img_ir_enable_wake (s/RC_FILTER_WAKUP/RC_FILTER_WAKEUP/).
- Use the new generic filtering interface rather than creating the sysfs
  files in the driver. This rearranges the code a bit, so as to use an
  array of 2 filters (normal and wake) rather than separate struct
  members for each, and passes the array index around between functions
  rather than the pointer to the filter.
- Make tolerance of hardware decoder timings configurable per protocol
  rather than being fixed at 10% for all protocols. This allows the
  tolerance of the Sharp protocol timings in particular to be increased.
- Extend the scancode() decoder callback to handle full 32bit scancodes.
  Previously negative scancodes were treated specially, and indicated
  repeat codes or invalid raw data, but 32bit NEC may result in a
  scancode with the top bit set. Therefore change the scancode() return
  value to simply indicate success/fail/repeat, and add an extra
  scancode output pointer parameter that must have been written by the
  callback if it returns IMG_IR_SCANCODE.
- Add a debug message for when the scancode() callback rejects the data.
- Remove the dynamic registration and unregistration of protocol decoder
  timings. It didn't really get us much and it complicated locking and
  load ordering.
- Separate clock rate specific data in the decoder timings structure so
  that it can be more easily shared between instantiations of the
  driver. A new struct img_ir_reg_timings stores the calculated clock
  rate specific register values for the timings. This allows us to make
  more widespread use of const on decoder timings.
- Simplify locking of decoders, they're now only modified when
  preprocessed, and all other use is after that, so preprocessing is the
  only place locking is required.
- Minor cosmetic changes (variable naming e.g. s/ir_dev/rdev/ in
  img_ir_set_protocol).
- Use spin_lock_irq() instead of spin_lock_irqsave() in various bits of
  code that aren't accessible from hard interrupt context.
- Fix rc_map.rc_type initialisation to use __ffs64(proto_mask).
- Fix img_ir_allowed_protos() to return a protocol mask in a u64 rather
  than an unsigned long.
- Fix change_protocol to accept a zero protocol mask (for when none is
  written to /sys/class/rc/rcX/protocols).
- Use setup_timer() macro for the end timer rather than using
  init_timer() and setting function pointer and data explicitly.
- Stop the end_timer (for keyups after repeat code timeout) safely on
  removal and protocol switch.
---
 drivers/media/rc/img-ir/img-ir-hw.c | 1032 +++
 drivers/media/rc/img-ir/img-ir-hw.h |  269 +
 2 files changed, 1301 insertions(+)
 create mode 100644 drivers/media/rc/img-ir/img-ir-hw.c
 create mode 100644 drivers/media/rc/img-ir/img-ir-hw.h

diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
b/drivers/media/rc/img-ir/img-ir-hw.c
new file mode 100644
index 000..21c8bbc
--- /dev/null
+++ b/drivers/media/rc/img-ir/img-ir-hw.c
@@ -0,0 +1,1032 @@
+/*
+ * ImgTec IR Hardware Decoder found in PowerDown Controller.
+ *
+ * Copyright 2010-2014 Imagination Technologies Ltd.
+ *
+ * This ties into the input subsystem using the RC-core. Protocol support is
+ * provided in separate modules which provide the parameters and scancode
+ * translation functions to set up the hardware decoder and interpret the
+ * resulting input.
+ */
+
+#include linux/bitops.h
+#include linux/clk.h
+#include linux/interrupt.h
+#include linux/spinlock.h
+#include linux/timer.h
+#include media/rc-core.h
+#include img-ir.h
+
+/* Decoders lock (only modified to preprocess them) */
+static DEFINE_SPINLOCK(img_ir_decoders_lock);
+
+static bool img_ir_decoders_preprocessed;
+static struct img_ir_decoder *img_ir_decoders[] = {
+   NULL
+};
+
+#define IMG_IR_F_FILTERBIT

  1   2   >