Re: [PATCH v3 2/3] media: rc: add driver for Amlogic Meson IR remote receiver

2014-11-26 Thread Carlo Caione
On Wed, Nov 26, 2014 at 4:04 PM, Mauro Carvalho Chehab
 wrote:
> Em Tue, 18 Nov 2014 21:22:34 +0100
> Beniamino Galvani  escreveu:
>
>> Amlogic Meson SoCs include a infrared remote control receiver that can
>> operate in two modes: "NEC" mode in which the hardware decodes frames
>> using the NEC IR protocol, and "general" mode in which the receiver
>> simply reports the duration of pulses and spaces for software
>> decoding.
>>
>> This is a driver for the IR receiver that implements software decoding
>> of received frames.
>>
>> Signed-off-by: Beniamino Galvani 
>> ---
>>  MAINTAINERS |   1 +
>>  drivers/media/rc/Kconfig|  11 +++
>>  drivers/media/rc/Makefile   |   1 +
>>  drivers/media/rc/meson-ir.c | 216 
>> 
>>  4 files changed, 229 insertions(+)
>>  create mode 100644 drivers/media/rc/meson-ir.c
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 0662378..f1bc045 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -850,6 +850,7 @@ ARM/Amlogic MesonX SoC support
>>  M:   Carlo Caione 
>>  L:   linux-arm-ker...@lists.infradead.org (moderated for non-subscribers)
>>  S:   Maintained
>> +F:   drivers/media/rc/meson-ir.c
>>  N:   meson[x68]
>
> Hmm... you're putting this driver at Carlo's maintenance shoulders.
>
> I need his ack in order to apply this patch.

Acked-by: Carlo Caione 


-- 
Carlo Caione
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3 2/3] media: rc: add driver for Amlogic Meson IR remote receiver

2014-11-26 Thread Mauro Carvalho Chehab
Em Tue, 18 Nov 2014 21:22:34 +0100
Beniamino Galvani  escreveu:

> Amlogic Meson SoCs include a infrared remote control receiver that can
> operate in two modes: "NEC" mode in which the hardware decodes frames
> using the NEC IR protocol, and "general" mode in which the receiver
> simply reports the duration of pulses and spaces for software
> decoding.
> 
> This is a driver for the IR receiver that implements software decoding
> of received frames.
> 
> Signed-off-by: Beniamino Galvani 
> ---
>  MAINTAINERS |   1 +
>  drivers/media/rc/Kconfig|  11 +++
>  drivers/media/rc/Makefile   |   1 +
>  drivers/media/rc/meson-ir.c | 216 
> 
>  4 files changed, 229 insertions(+)
>  create mode 100644 drivers/media/rc/meson-ir.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 0662378..f1bc045 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -850,6 +850,7 @@ ARM/Amlogic MesonX SoC support
>  M:   Carlo Caione 
>  L:   linux-arm-ker...@lists.infradead.org (moderated for non-subscribers)
>  S:   Maintained
> +F:   drivers/media/rc/meson-ir.c
>  N:   meson[x68]

Hmm... you're putting this driver at Carlo's maintenance shoulders.

I need his ack in order to apply this patch.

Regards,
Mauro

>  
>  ARM/ATMEL AT91RM9200 AND AT91SAM ARM ARCHITECTURES
> diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
> index 1aea732..ddfab25 100644
> --- a/drivers/media/rc/Kconfig
> +++ b/drivers/media/rc/Kconfig
> @@ -223,6 +223,17 @@ config IR_FINTEK
>  To compile this driver as a module, choose M here: the
>  module will be called fintek-cir.
>  
> +config IR_MESON
> + tristate "Amlogic Meson IR remote receiver"
> + depends on RC_CORE
> + depends on ARCH_MESON || COMPILE_TEST
> + ---help---
> +Say Y if you want to use the IR remote receiver available
> +on Amlogic Meson SoCs.
> +
> +To compile this driver as a module, choose M here: the
> +module will be called meson-ir.
> +
>  config IR_NUVOTON
>   tristate "Nuvoton w836x7hg Consumer Infrared Transceiver"
>   depends on PNP
> diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
> index 8f509e0..379a5c0 100644
> --- a/drivers/media/rc/Makefile
> +++ b/drivers/media/rc/Makefile
> @@ -22,6 +22,7 @@ obj-$(CONFIG_IR_IMON) += imon.o
>  obj-$(CONFIG_IR_ITE_CIR) += ite-cir.o
>  obj-$(CONFIG_IR_MCEUSB) += mceusb.o
>  obj-$(CONFIG_IR_FINTEK) += fintek-cir.o
> +obj-$(CONFIG_IR_MESON) += meson-ir.o
>  obj-$(CONFIG_IR_NUVOTON) += nuvoton-cir.o
>  obj-$(CONFIG_IR_ENE) += ene_ir.o
>  obj-$(CONFIG_IR_REDRAT3) += redrat3.o
> diff --git a/drivers/media/rc/meson-ir.c b/drivers/media/rc/meson-ir.c
> new file mode 100644
> index 000..fcc3b82
> --- /dev/null
> +++ b/drivers/media/rc/meson-ir.c
> @@ -0,0 +1,216 @@
> +/*
> + * Driver for Amlogic Meson IR remote receiver
> + *
> + * Copyright (C) 2014 Beniamino Galvani 
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * version 2 as published by the Free Software Foundation.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program. If not, see .
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +
> +#define DRIVER_NAME  "meson-ir"
> +
> +#define IR_DEC_LDR_ACTIVE0x00
> +#define IR_DEC_LDR_IDLE  0x04
> +#define IR_DEC_LDR_REPEAT0x08
> +#define IR_DEC_BIT_0 0x0c
> +#define IR_DEC_REG0  0x10
> +#define IR_DEC_FRAME 0x14
> +#define IR_DEC_STATUS0x18
> +#define IR_DEC_REG1  0x1c
> +
> +#define REG0_RATE_MASK   (BIT(11) - 1)
> +
> +#define REG1_MODE_MASK   (BIT(7) | BIT(8))
> +#define REG1_MODE_NEC(0 << 7)
> +#define REG1_MODE_GENERAL(2 << 7)
> +
> +#define REG1_TIME_IV_SHIFT   16
> +#define REG1_TIME_IV_MASK((BIT(13) - 1) << REG1_TIME_IV_SHIFT)
> +
> +#define REG1_IRQSEL_MASK (BIT(2) | BIT(3))
> +#define REG1_IRQSEL_NEC_MODE (0 << 2)
> +#define REG1_IRQSEL_RISE_FALL(1 << 2)
> +#define REG1_IRQSEL_FALL (2 << 2)
> +#define REG1_IRQSEL_RISE (3 << 2)
> +
> +#define REG1_RESET   BIT(0)
> +#define REG1_ENABLE  BIT(15)
> +
> +#define STATUS_IR_DEC_IN BIT(8)
> +
> +#define MESON_TRATE  10  /* us */
> +
> +struct meson_ir {
> + void __iomem*reg;
> + struct rc_dev   *rc;
> + int irq;
> + spinlock_t  lock;
> +};
> +
> +static void meson_ir_set_mask(struct meson_ir *ir, unsigned int reg,
> +   u32 mask, u32 value)
> +{
> + u32 data;
> +
> + data = readl(ir->reg + reg);
> + data &= ~mask;
> + data |= (value & mask);
> + writel(data, ir->reg + reg);
> +}
> +
> +static irqreturn_t meson_ir_irq(int irqn

[PATCH v3 2/3] media: rc: add driver for Amlogic Meson IR remote receiver

2014-11-18 Thread Beniamino Galvani
Amlogic Meson SoCs include a infrared remote control receiver that can
operate in two modes: "NEC" mode in which the hardware decodes frames
using the NEC IR protocol, and "general" mode in which the receiver
simply reports the duration of pulses and spaces for software
decoding.

This is a driver for the IR receiver that implements software decoding
of received frames.

Signed-off-by: Beniamino Galvani 
---
 MAINTAINERS |   1 +
 drivers/media/rc/Kconfig|  11 +++
 drivers/media/rc/Makefile   |   1 +
 drivers/media/rc/meson-ir.c | 216 
 4 files changed, 229 insertions(+)
 create mode 100644 drivers/media/rc/meson-ir.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 0662378..f1bc045 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -850,6 +850,7 @@ ARM/Amlogic MesonX SoC support
 M: Carlo Caione 
 L: linux-arm-ker...@lists.infradead.org (moderated for non-subscribers)
 S: Maintained
+F: drivers/media/rc/meson-ir.c
 N: meson[x68]
 
 ARM/ATMEL AT91RM9200 AND AT91SAM ARM ARCHITECTURES
diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 1aea732..ddfab25 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -223,6 +223,17 @@ config IR_FINTEK
   To compile this driver as a module, choose M here: the
   module will be called fintek-cir.
 
+config IR_MESON
+   tristate "Amlogic Meson IR remote receiver"
+   depends on RC_CORE
+   depends on ARCH_MESON || COMPILE_TEST
+   ---help---
+  Say Y if you want to use the IR remote receiver available
+  on Amlogic Meson SoCs.
+
+  To compile this driver as a module, choose M here: the
+  module will be called meson-ir.
+
 config IR_NUVOTON
tristate "Nuvoton w836x7hg Consumer Infrared Transceiver"
depends on PNP
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index 8f509e0..379a5c0 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -22,6 +22,7 @@ obj-$(CONFIG_IR_IMON) += imon.o
 obj-$(CONFIG_IR_ITE_CIR) += ite-cir.o
 obj-$(CONFIG_IR_MCEUSB) += mceusb.o
 obj-$(CONFIG_IR_FINTEK) += fintek-cir.o
+obj-$(CONFIG_IR_MESON) += meson-ir.o
 obj-$(CONFIG_IR_NUVOTON) += nuvoton-cir.o
 obj-$(CONFIG_IR_ENE) += ene_ir.o
 obj-$(CONFIG_IR_REDRAT3) += redrat3.o
diff --git a/drivers/media/rc/meson-ir.c b/drivers/media/rc/meson-ir.c
new file mode 100644
index 000..fcc3b82
--- /dev/null
+++ b/drivers/media/rc/meson-ir.c
@@ -0,0 +1,216 @@
+/*
+ * Driver for Amlogic Meson IR remote receiver
+ *
+ * Copyright (C) 2014 Beniamino Galvani 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define DRIVER_NAME"meson-ir"
+
+#define IR_DEC_LDR_ACTIVE  0x00
+#define IR_DEC_LDR_IDLE0x04
+#define IR_DEC_LDR_REPEAT  0x08
+#define IR_DEC_BIT_0   0x0c
+#define IR_DEC_REG00x10
+#define IR_DEC_FRAME   0x14
+#define IR_DEC_STATUS  0x18
+#define IR_DEC_REG10x1c
+
+#define REG0_RATE_MASK (BIT(11) - 1)
+
+#define REG1_MODE_MASK (BIT(7) | BIT(8))
+#define REG1_MODE_NEC  (0 << 7)
+#define REG1_MODE_GENERAL  (2 << 7)
+
+#define REG1_TIME_IV_SHIFT 16
+#define REG1_TIME_IV_MASK  ((BIT(13) - 1) << REG1_TIME_IV_SHIFT)
+
+#define REG1_IRQSEL_MASK   (BIT(2) | BIT(3))
+#define REG1_IRQSEL_NEC_MODE   (0 << 2)
+#define REG1_IRQSEL_RISE_FALL  (1 << 2)
+#define REG1_IRQSEL_FALL   (2 << 2)
+#define REG1_IRQSEL_RISE   (3 << 2)
+
+#define REG1_RESET BIT(0)
+#define REG1_ENABLEBIT(15)
+
+#define STATUS_IR_DEC_IN   BIT(8)
+
+#define MESON_TRATE10  /* us */
+
+struct meson_ir {
+   void __iomem*reg;
+   struct rc_dev   *rc;
+   int irq;
+   spinlock_t  lock;
+};
+
+static void meson_ir_set_mask(struct meson_ir *ir, unsigned int reg,
+ u32 mask, u32 value)
+{
+   u32 data;
+
+   data = readl(ir->reg + reg);
+   data &= ~mask;
+   data |= (value & mask);
+   writel(data, ir->reg + reg);
+}
+
+static irqreturn_t meson_ir_irq(int irqno, void *dev_id)
+{
+   struct meson_ir *ir = dev_id;
+   u32 duration;
+   DEFINE_IR_RAW_EVENT(rawir);
+
+   spin_lock(&ir->lock);
+
+   duration = readl(ir->reg + IR_DEC_REG1);
+   duration = (duration & REG1_TIME_IV_MASK) >> REG1_TIME_IV_SHIFT;
+   rawir.duration = US_TO_NS(duration * MESON_TRATE);
+
+   rawir.pulse = !!(readl(ir->reg + IR_DEC_STATUS) & STATUS_IR_DEC_IN);
+
+   ir_raw_eve