linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] media: rc: add support for Amlogic Meson IR receiver
@ 2014-10-12 20:01 Beniamino Galvani
  2014-10-12 20:01 ` [PATCH 1/3] media: rc: add driver for Amlogic Meson IR remote receiver Beniamino Galvani
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Beniamino Galvani @ 2014-10-12 20:01 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, linux-arm-kernel, devicetree,
	Carlo Caione, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Jerry Cao, Victor Wan,
	Beniamino Galvani

Hi,

this is a driver for the IR receiver available in Amlogic Meson6 and
Meson8 SoCs. The device can operate in two modes: in "NEC" mode the
hardware can decode frames using the NEC IR protocol, while in
"general" mode the receiver simply reports the duration of pulses and
spaces for software decoding.

In order to have the maximum compatibility with different protocols
the driver implements software decoding.

The third patch (dts files) depends on some other patchsets [1][2]
that are still under review, so at the moment is not meant to be
merged.

[1] https://lkml.org/lkml/2014/10/5/162
[2] https://lkml.org/lkml/2014/10/7/712

Beniamino Galvani (3):
  media: rc: add driver for Amlogic Meson IR remote receiver
  media: rc: meson: document device tree bindings
  ARM: dts: meson: add dts nodes for IR receiver

 .../devicetree/bindings/media/meson-ir.txt         |  14 ++
 arch/arm/boot/dts/meson.dtsi                       |   7 +
 arch/arm/boot/dts/meson8-vega-s89e.dts             |   6 +
 arch/arm/boot/dts/meson8.dtsi                      |   7 +
 drivers/media/rc/Kconfig                           |  11 ++
 drivers/media/rc/Makefile                          |   1 +
 drivers/media/rc/meson-ir.c                        | 214 +++++++++++++++++++++
 7 files changed, 260 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/meson-ir.txt
 create mode 100644 drivers/media/rc/meson-ir.c

-- 
1.9.1


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

* [PATCH 1/3] media: rc: add driver for Amlogic Meson IR remote receiver
  2014-10-12 20:01 [PATCH 0/3] media: rc: add support for Amlogic Meson IR receiver Beniamino Galvani
@ 2014-10-12 20:01 ` Beniamino Galvani
  2014-11-03 13:14   ` Mauro Carvalho Chehab
  2014-10-12 20:01 ` [PATCH 2/3] media: rc: meson: document device tree bindings Beniamino Galvani
  2014-10-12 20:01 ` [PATCH 3/3] ARM: dts: meson: add dts nodes for IR receiver Beniamino Galvani
  2 siblings, 1 reply; 7+ messages in thread
From: Beniamino Galvani @ 2014-10-12 20:01 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, linux-arm-kernel, devicetree,
	Carlo Caione, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Jerry Cao, Victor Wan,
	Beniamino Galvani

Amlogic Meson SoCs include a infrared remote control receiver that can
operate in two modes: in "NEC" mode the hardware can decode frames
using the NEC IR protocol, while in "general" mode the receiver simply
reports the duration of pulses and spaces for software decoding.

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

Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
---
 drivers/media/rc/Kconfig    |  11 +++
 drivers/media/rc/Makefile   |   1 +
 drivers/media/rc/meson-ir.c | 214 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 226 insertions(+)
 create mode 100644 drivers/media/rc/meson-ir.c

diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 8ce0810..2d742e2 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
+	---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 0989f94..06859bf 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 0000000..0900ece
--- /dev/null
+++ b/drivers/media/rc/meson-ir.c
@@ -0,0 +1,214 @@
+/*
+ * Driver for Amlogic Meson IR remote receiver
+ *
+ * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/of_platform.h>
+#include <linux/spinlock.h>
+
+#include <media/rc-core.h>
+
+#define DRIVER_NAME		"meson-ir"
+
+#define IR_DEC_LDR_ACTIVE	0x00
+#define IR_DEC_LDR_IDLE		0x04
+#define IR_DEC_LDR_REPEAT	0x08
+#define IR_DEC_BIT_0		0x0c
+#define IR_DEC_REG0		0x10
+#define IR_DEC_FRAME		0x14
+#define IR_DEC_STATUS		0x18
+#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 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_event_store_with_filter(ir->rc, &rawir);
+	ir_raw_event_handle(ir->rc);
+
+	spin_unlock(&ir->lock);
+
+	return IRQ_HANDLED;
+}
+
+static int meson_ir_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *node = dev->of_node;
+	struct resource *res;
+	const char *map_name;
+	struct meson_ir *ir;
+	int ret;
+
+	ir = devm_kzalloc(dev, sizeof(struct meson_ir), GFP_KERNEL);
+	if (!ir)
+		return -ENOMEM;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	ir->reg = devm_ioremap_resource(dev, res);
+	if (IS_ERR(ir->reg)) {
+		dev_err(dev, "failed to map registers\n");
+		return PTR_ERR(ir->reg);
+	}
+
+	ir->irq = platform_get_irq(pdev, 0);
+	if (ir->irq < 0) {
+		dev_err(dev, "no irq resource\n");
+		return ir->irq;
+	}
+
+	ir->rc = rc_allocate_device();
+	if (!ir->rc) {
+		dev_err(dev, "failed to allocate rc device\n");
+		return -ENOMEM;
+	}
+
+	ir->rc->priv = ir;
+	ir->rc->input_name = DRIVER_NAME;
+	ir->rc->input_phys = DRIVER_NAME "/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;
+	map_name = of_get_property(node, "linux,rc-map-name", NULL);
+	ir->rc->map_name = map_name ? map_name : RC_MAP_EMPTY;
+	ir->rc->dev.parent = dev;
+	ir->rc->driver_type = RC_DRIVER_IR_RAW;
+	ir->rc->allowed_protocols = RC_BIT_ALL;
+	ir->rc->rx_resolution = US_TO_NS(MESON_TRATE);
+	ir->rc->timeout = MS_TO_NS(200);
+	ir->rc->driver_name = DRIVER_NAME;
+
+	spin_lock_init(&ir->lock);
+	platform_set_drvdata(pdev, ir);
+
+	ret = rc_register_device(ir->rc);
+	if (ret) {
+		dev_err(dev, "failed to register rc device\n");
+		goto out_free;
+	}
+
+	ret = devm_request_irq(dev, ir->irq, meson_ir_irq, 0, "ir-meson", ir);
+	if (ret) {
+		dev_err(dev, "failed to request irq\n");
+		goto out_unreg;
+	}
+
+	/* Reset the decoder */
+	meson_ir_set_mask(ir, IR_DEC_REG1, REG1_RESET, REG1_RESET);
+	meson_ir_set_mask(ir, IR_DEC_REG1, REG1_RESET, 0);
+	/* Set general operation mode */
+	meson_ir_set_mask(ir, IR_DEC_REG1, REG1_MODE_MASK, REG1_MODE_GENERAL);
+	/* Set rate */
+	meson_ir_set_mask(ir, IR_DEC_REG0, REG0_RATE_MASK, MESON_TRATE - 1);
+	/* IRQ on rising and falling edges */
+	meson_ir_set_mask(ir, IR_DEC_REG1, REG1_IRQSEL_MASK,
+			  REG1_IRQSEL_RISE_FALL);
+	/* Enable the decoder */
+	meson_ir_set_mask(ir, IR_DEC_REG1, REG1_ENABLE, REG1_ENABLE);
+
+	dev_info(dev, "receiver initialized\n");
+
+	return 0;
+out_unreg:
+	rc_unregister_device(ir->rc);
+out_free:
+	rc_free_device(ir->rc);
+
+	return ret;
+}
+
+static int meson_ir_remove(struct platform_device *pdev)
+{
+	struct meson_ir *ir = platform_get_drvdata(pdev);
+	unsigned long flags;
+
+	/* Disable the decoder */
+	spin_lock_irqsave(&ir->lock, flags);
+	meson_ir_set_mask(ir, IR_DEC_REG1, REG1_ENABLE, 0);
+	spin_unlock_irqrestore(&ir->lock, flags);
+
+	rc_unregister_device(ir->rc);
+
+	return 0;
+}
+
+static const struct of_device_id meson_ir_match[] = {
+	{ .compatible = "amlogic,meson6-ir" },
+	{ },
+};
+
+static struct platform_driver meson_ir_driver = {
+	.probe		= meson_ir_probe,
+	.remove		= meson_ir_remove,
+	.driver = {
+		.name		= DRIVER_NAME,
+		.of_match_table	= meson_ir_match,
+	},
+};
+
+module_platform_driver(meson_ir_driver);
+
+MODULE_DESCRIPTION("Amlogic Meson IR remote receiver driver");
+MODULE_AUTHOR("Beniamino Galvani <b.galvani@gmail.com>");
+MODULE_LICENSE("GPL v2");
-- 
1.9.1


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

* [PATCH 2/3] media: rc: meson: document device tree bindings
  2014-10-12 20:01 [PATCH 0/3] media: rc: add support for Amlogic Meson IR receiver Beniamino Galvani
  2014-10-12 20:01 ` [PATCH 1/3] media: rc: add driver for Amlogic Meson IR remote receiver Beniamino Galvani
@ 2014-10-12 20:01 ` Beniamino Galvani
  2014-10-12 20:01 ` [PATCH 3/3] ARM: dts: meson: add dts nodes for IR receiver Beniamino Galvani
  2 siblings, 0 replies; 7+ messages in thread
From: Beniamino Galvani @ 2014-10-12 20:01 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, linux-arm-kernel, devicetree,
	Carlo Caione, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Jerry Cao, Victor Wan,
	Beniamino Galvani

This adds binding documentation for the infrared remote control
receiver available in Amlogic Meson SoCs.

Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
---
 Documentation/devicetree/bindings/media/meson-ir.txt | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/meson-ir.txt

diff --git a/Documentation/devicetree/bindings/media/meson-ir.txt b/Documentation/devicetree/bindings/media/meson-ir.txt
new file mode 100644
index 0000000..407848e
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/meson-ir.txt
@@ -0,0 +1,14 @@
+* Amlogic Meson IR remote control receiver
+
+Required properties:
+ - compatible	: should be "amlogic,meson6-ir"
+ - reg		: physical base address and length of the device registers
+ - interrupts	: a single specifier for the interrupt from the device
+
+Example:
+
+	ir-receiver@c8100480 {
+		compatible= "amlogic,meson6-ir";
+		reg = <0xc8100480 0x20>;
+		interrupts = <0 15 1>;
+	};
-- 
1.9.1


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

* [PATCH 3/3] ARM: dts: meson: add dts nodes for IR receiver
  2014-10-12 20:01 [PATCH 0/3] media: rc: add support for Amlogic Meson IR receiver Beniamino Galvani
  2014-10-12 20:01 ` [PATCH 1/3] media: rc: add driver for Amlogic Meson IR remote receiver Beniamino Galvani
  2014-10-12 20:01 ` [PATCH 2/3] media: rc: meson: document device tree bindings Beniamino Galvani
@ 2014-10-12 20:01 ` Beniamino Galvani
  2 siblings, 0 replies; 7+ messages in thread
From: Beniamino Galvani @ 2014-10-12 20:01 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, linux-arm-kernel, devicetree,
	Carlo Caione, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Jerry Cao, Victor Wan,
	Beniamino Galvani

Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
---
 arch/arm/boot/dts/meson.dtsi           | 7 +++++++
 arch/arm/boot/dts/meson8-vega-s89e.dts | 6 ++++++
 arch/arm/boot/dts/meson8.dtsi          | 7 +++++++
 3 files changed, 20 insertions(+)

diff --git a/arch/arm/boot/dts/meson.dtsi b/arch/arm/boot/dts/meson.dtsi
index 7d27f12..a14461c 100644
--- a/arch/arm/boot/dts/meson.dtsi
+++ b/arch/arm/boot/dts/meson.dtsi
@@ -108,5 +108,12 @@
 			clocks = <&clk81>;
 			status = "disabled";
 		};
+
+		ir_receiver: ir-receiver@c8100480 {
+			compatible= "amlogic,meson6-ir";
+			reg = <0xc8100480 0x20>;
+			interrupts = <0 15 1>;
+			status = "disabled";
+		};
 	};
 }; /* end of / */
diff --git a/arch/arm/boot/dts/meson8-vega-s89e.dts b/arch/arm/boot/dts/meson8-vega-s89e.dts
index 70a05c1..5ea54c8 100644
--- a/arch/arm/boot/dts/meson8-vega-s89e.dts
+++ b/arch/arm/boot/dts/meson8-vega-s89e.dts
@@ -77,3 +77,9 @@
 	pinctrl-names = "default";
 	pinctrl-0 = <&uart_ao_a>;
 };
+
+&ir_receiver {
+	status = "okay";
+	pinctrl-names = "default";
+	pinctrl-0 = <&ir_pins>;
+};
diff --git a/arch/arm/boot/dts/meson8.dtsi b/arch/arm/boot/dts/meson8.dtsi
index 59c3af0..ea98ed3 100644
--- a/arch/arm/boot/dts/meson8.dtsi
+++ b/arch/arm/boot/dts/meson8.dtsi
@@ -122,6 +122,13 @@
 				function = "uart_ao";
 			};
 		};
+
+		ir_pins: ir_pins {
+			ir_pins {
+				pins = "remote_input";
+				function = "remote";
+			};
+		};
 	};
 
 }; /* end of / */
-- 
1.9.1


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

* Re: [PATCH 1/3] media: rc: add driver for Amlogic Meson IR remote receiver
  2014-10-12 20:01 ` [PATCH 1/3] media: rc: add driver for Amlogic Meson IR remote receiver Beniamino Galvani
@ 2014-11-03 13:14   ` Mauro Carvalho Chehab
  2014-11-03 20:54     ` Beniamino Galvani
  0 siblings, 1 reply; 7+ messages in thread
From: Mauro Carvalho Chehab @ 2014-11-03 13:14 UTC (permalink / raw)
  To: Beniamino Galvani
  Cc: linux-media, linux-kernel, linux-arm-kernel, devicetree,
	Carlo Caione, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Jerry Cao, Victor Wan

Em Sun, 12 Oct 2014 22:01:53 +0200
Beniamino Galvani <b.galvani@gmail.com> escreveu:

> Amlogic Meson SoCs include a infrared remote control receiver that can
> operate in two modes: in "NEC" mode the hardware can decode frames
> using the NEC IR protocol, while in "general" mode the receiver simply
> reports the duration of pulses and spaces for software decoding.
> 
> This is a driver for the IR receiver that uses software decoding of
> received frames.

There are a few checkpatch warnings there:

WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#71: 
new file mode 100644

WARNING: Missing a blank line after declarations
#151: FILE: drivers/media/rc/meson-ir.c:76:
+	u32 duration;
+	DEFINE_IR_RAW_EVENT(rawir);

WARNING: DT compatible string "amlogic,meson6-ir" appears un-documented -- check ./Documentation/devicetree/bindings/
#272: FILE: drivers/media/rc/meson-ir.c:197:
+	{ .compatible = "amlogic,meson6-ir" },

total: 0 errors, 3 warnings, 238 lines checked

patches/lmml_26418_1_3_media_rc_add_driver_for_amlogic_meson_ir_remote_receiver.patch has style problems, please review.

I'm seeing that the DT patches are there, after this one. The best
would be to add them before in the series.

Please add also an entry at the MAINTAINERS file.


> 
> Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
> ---
>  drivers/media/rc/Kconfig    |  11 +++
>  drivers/media/rc/Makefile   |   1 +
>  drivers/media/rc/meson-ir.c | 214 ++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 226 insertions(+)
>  create mode 100644 drivers/media/rc/meson-ir.c
> 
> diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
> index 8ce0810..2d742e2 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

Please add COMPILE_TEST too, as we want to be able to compile it on
x86 and other archs, in order to check if the driver builds fine and
to enable the static analyzers to look into this code.

> +	---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 0989f94..06859bf 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 0000000..0900ece
> --- /dev/null
> +++ b/drivers/media/rc/meson-ir.c
> @@ -0,0 +1,214 @@
> +/*
> + * Driver for Amlogic Meson IR remote receiver
> + *
> + * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com>
> + *
> + * 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 <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <linux/interrupt.h>
> +#include <linux/module.h>
> +#include <linux/of_platform.h>
> +#include <linux/spinlock.h>
> +
> +#include <media/rc-core.h>
> +
> +#define DRIVER_NAME		"meson-ir"
> +
> +#define IR_DEC_LDR_ACTIVE	0x00
> +#define IR_DEC_LDR_IDLE		0x04
> +#define IR_DEC_LDR_REPEAT	0x08
> +#define IR_DEC_BIT_0		0x0c
> +#define IR_DEC_REG0		0x10
> +#define IR_DEC_FRAME		0x14
> +#define IR_DEC_STATUS		0x18
> +#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 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_event_store_with_filter(ir->rc, &rawir);
> +	ir_raw_event_handle(ir->rc);
> +
> +	spin_unlock(&ir->lock);
> +
> +	return IRQ_HANDLED;
> +}
> +
> +static int meson_ir_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct device_node *node = dev->of_node;
> +	struct resource *res;
> +	const char *map_name;
> +	struct meson_ir *ir;
> +	int ret;
> +
> +	ir = devm_kzalloc(dev, sizeof(struct meson_ir), GFP_KERNEL);
> +	if (!ir)
> +		return -ENOMEM;
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> +	ir->reg = devm_ioremap_resource(dev, res);
> +	if (IS_ERR(ir->reg)) {
> +		dev_err(dev, "failed to map registers\n");
> +		return PTR_ERR(ir->reg);
> +	}
> +
> +	ir->irq = platform_get_irq(pdev, 0);
> +	if (ir->irq < 0) {
> +		dev_err(dev, "no irq resource\n");
> +		return ir->irq;
> +	}
> +
> +	ir->rc = rc_allocate_device();
> +	if (!ir->rc) {
> +		dev_err(dev, "failed to allocate rc device\n");
> +		return -ENOMEM;
> +	}
> +
> +	ir->rc->priv = ir;
> +	ir->rc->input_name = DRIVER_NAME;
> +	ir->rc->input_phys = DRIVER_NAME "/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;

I don't like very much the idea of filling it like that. From where those
numbers came? Could you add a define for them somewhere?

> +	map_name = of_get_property(node, "linux,rc-map-name", NULL);
> +	ir->rc->map_name = map_name ? map_name : RC_MAP_EMPTY;
> +	ir->rc->dev.parent = dev;
> +	ir->rc->driver_type = RC_DRIVER_IR_RAW;
> +	ir->rc->allowed_protocols = RC_BIT_ALL;
> +	ir->rc->rx_resolution = US_TO_NS(MESON_TRATE);
> +	ir->rc->timeout = MS_TO_NS(200);
> +	ir->rc->driver_name = DRIVER_NAME;
> +
> +	spin_lock_init(&ir->lock);
> +	platform_set_drvdata(pdev, ir);
> +
> +	ret = rc_register_device(ir->rc);
> +	if (ret) {
> +		dev_err(dev, "failed to register rc device\n");
> +		goto out_free;
> +	}
> +
> +	ret = devm_request_irq(dev, ir->irq, meson_ir_irq, 0, "ir-meson", ir);
> +	if (ret) {
> +		dev_err(dev, "failed to request irq\n");
> +		goto out_unreg;
> +	}
> +
> +	/* Reset the decoder */
> +	meson_ir_set_mask(ir, IR_DEC_REG1, REG1_RESET, REG1_RESET);
> +	meson_ir_set_mask(ir, IR_DEC_REG1, REG1_RESET, 0);
> +	/* Set general operation mode */
> +	meson_ir_set_mask(ir, IR_DEC_REG1, REG1_MODE_MASK, REG1_MODE_GENERAL);
> +	/* Set rate */
> +	meson_ir_set_mask(ir, IR_DEC_REG0, REG0_RATE_MASK, MESON_TRATE - 1);
> +	/* IRQ on rising and falling edges */
> +	meson_ir_set_mask(ir, IR_DEC_REG1, REG1_IRQSEL_MASK,
> +			  REG1_IRQSEL_RISE_FALL);
> +	/* Enable the decoder */
> +	meson_ir_set_mask(ir, IR_DEC_REG1, REG1_ENABLE, REG1_ENABLE);
> +
> +	dev_info(dev, "receiver initialized\n");
> +
> +	return 0;
> +out_unreg:
> +	rc_unregister_device(ir->rc);
> +out_free:
> +	rc_free_device(ir->rc);
> +
> +	return ret;
> +}
> +
> +static int meson_ir_remove(struct platform_device *pdev)
> +{
> +	struct meson_ir *ir = platform_get_drvdata(pdev);
> +	unsigned long flags;
> +
> +	/* Disable the decoder */
> +	spin_lock_irqsave(&ir->lock, flags);
> +	meson_ir_set_mask(ir, IR_DEC_REG1, REG1_ENABLE, 0);
> +	spin_unlock_irqrestore(&ir->lock, flags);
> +
> +	rc_unregister_device(ir->rc);
> +
> +	return 0;
> +}
> +
> +static const struct of_device_id meson_ir_match[] = {
> +	{ .compatible = "amlogic,meson6-ir" },
> +	{ },
> +};
> +
> +static struct platform_driver meson_ir_driver = {
> +	.probe		= meson_ir_probe,
> +	.remove		= meson_ir_remove,
> +	.driver = {
> +		.name		= DRIVER_NAME,
> +		.of_match_table	= meson_ir_match,
> +	},
> +};
> +
> +module_platform_driver(meson_ir_driver);
> +
> +MODULE_DESCRIPTION("Amlogic Meson IR remote receiver driver");
> +MODULE_AUTHOR("Beniamino Galvani <b.galvani@gmail.com>");
> +MODULE_LICENSE("GPL v2");

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

* Re: [PATCH 1/3] media: rc: add driver for Amlogic Meson IR remote receiver
  2014-11-03 13:14   ` Mauro Carvalho Chehab
@ 2014-11-03 20:54     ` Beniamino Galvani
  2014-11-03 21:04       ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 7+ messages in thread
From: Beniamino Galvani @ 2014-11-03 20:54 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linux-media, linux-kernel, linux-arm-kernel, devicetree,
	Carlo Caione, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Jerry Cao, Victor Wan

On Mon, Nov 03, 2014 at 11:14:10AM -0200, Mauro Carvalho Chehab wrote:
> Em Sun, 12 Oct 2014 22:01:53 +0200
> Beniamino Galvani <b.galvani@gmail.com> escreveu:
> 
> > Amlogic Meson SoCs include a infrared remote control receiver that can
> > operate in two modes: in "NEC" mode the hardware can decode frames
> > using the NEC IR protocol, while in "general" mode the receiver simply
> > reports the duration of pulses and spaces for software decoding.
> > 
> > This is a driver for the IR receiver that uses software decoding of
> > received frames.
> 
> There are a few checkpatch warnings there:
> 
> WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
> #71: 
> new file mode 100644
> 
> WARNING: Missing a blank line after declarations
> #151: FILE: drivers/media/rc/meson-ir.c:76:
> +	u32 duration;
> +	DEFINE_IR_RAW_EVENT(rawir);

Here the macro is actually a variable definition and so it makes sense
to group it with the other definitions without blank lines. I checked
other rc drivers and many of them have a similar pattern. Could we
consider the warning as a false positive?

> 
> WARNING: DT compatible string "amlogic,meson6-ir" appears un-documented -- check ./Documentation/devicetree/bindings/
> #272: FILE: drivers/media/rc/meson-ir.c:197:
> +	{ .compatible = "amlogic,meson6-ir" },
> 
> total: 0 errors, 3 warnings, 238 lines checked
> 
> patches/lmml_26418_1_3_media_rc_add_driver_for_amlogic_meson_ir_remote_receiver.patch has style problems, please review.
> 
> I'm seeing that the DT patches are there, after this one. The best
> would be to add them before in the series.
> 
> Please add also an entry at the MAINTAINERS file.

I'll reorder the patches and add the maintainer entry.

> 
> 
> > 
> > Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
> > ---
> >  drivers/media/rc/Kconfig    |  11 +++
> >  drivers/media/rc/Makefile   |   1 +
> >  drivers/media/rc/meson-ir.c | 214 ++++++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 226 insertions(+)
> >  create mode 100644 drivers/media/rc/meson-ir.c
> > 
> > diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
> > index 8ce0810..2d742e2 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
> 
> Please add COMPILE_TEST too, as we want to be able to compile it on
> x86 and other archs, in order to check if the driver builds fine and
> to enable the static analyzers to look into this code.

Ok.

[...]

> > +
> > +	ir->rc->priv = ir;
> > +	ir->rc->input_name = DRIVER_NAME;
> > +	ir->rc->input_phys = DRIVER_NAME "/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;
> 
> I don't like very much the idea of filling it like that. From where those
> numbers came? Could you add a define for them somewhere?

I've seen that other drivers as gpio-ir-recv and sunxi-cir assign
those numbers to the fields of input_id but I couldn't find a
documentation of the meaning. If the assignments are not needed I will
drop them in the next version.

Beniamino

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

* Re: [PATCH 1/3] media: rc: add driver for Amlogic Meson IR remote receiver
  2014-11-03 20:54     ` Beniamino Galvani
@ 2014-11-03 21:04       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 7+ messages in thread
From: Mauro Carvalho Chehab @ 2014-11-03 21:04 UTC (permalink / raw)
  To: Beniamino Galvani
  Cc: linux-media, linux-kernel, linux-arm-kernel, devicetree,
	Carlo Caione, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Jerry Cao, Victor Wan

Em Mon, 03 Nov 2014 21:54:53 +0100
Beniamino Galvani <b.galvani@gmail.com> escreveu:

> On Mon, Nov 03, 2014 at 11:14:10AM -0200, Mauro Carvalho Chehab wrote:
> > Em Sun, 12 Oct 2014 22:01:53 +0200
> > Beniamino Galvani <b.galvani@gmail.com> escreveu:
> > 
> > > Amlogic Meson SoCs include a infrared remote control receiver that can
> > > operate in two modes: in "NEC" mode the hardware can decode frames
> > > using the NEC IR protocol, while in "general" mode the receiver simply
> > > reports the duration of pulses and spaces for software decoding.
> > > 
> > > This is a driver for the IR receiver that uses software decoding of
> > > received frames.
> > 
> > There are a few checkpatch warnings there:
> > 
> > WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
> > #71: 
> > new file mode 100644
> > 
> > WARNING: Missing a blank line after declarations
> > #151: FILE: drivers/media/rc/meson-ir.c:76:
> > +	u32 duration;
> > +	DEFINE_IR_RAW_EVENT(rawir);
> 
> Here the macro is actually a variable definition and so it makes sense
> to group it with the other definitions without blank lines. I checked
> other rc drivers and many of them have a similar pattern. Could we
> consider the warning as a false positive?

Yes, this is a false positive.

> 
> > 
> > WARNING: DT compatible string "amlogic,meson6-ir" appears un-documented -- check ./Documentation/devicetree/bindings/
> > #272: FILE: drivers/media/rc/meson-ir.c:197:
> > +	{ .compatible = "amlogic,meson6-ir" },
> > 
> > total: 0 errors, 3 warnings, 238 lines checked
> > 
> > patches/lmml_26418_1_3_media_rc_add_driver_for_amlogic_meson_ir_remote_receiver.patch has style problems, please review.
> > 
> > I'm seeing that the DT patches are there, after this one. The best
> > would be to add them before in the series.
> > 
> > Please add also an entry at the MAINTAINERS file.
> 
> I'll reorder the patches and add the maintainer entry.

Ok, thanks!

> 
> > 
> > 
> > > 
> > > Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
> > > ---
> > >  drivers/media/rc/Kconfig    |  11 +++
> > >  drivers/media/rc/Makefile   |   1 +
> > >  drivers/media/rc/meson-ir.c | 214 ++++++++++++++++++++++++++++++++++++++++++++
> > >  3 files changed, 226 insertions(+)
> > >  create mode 100644 drivers/media/rc/meson-ir.c
> > > 
> > > diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
> > > index 8ce0810..2d742e2 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
> > 
> > Please add COMPILE_TEST too, as we want to be able to compile it on
> > x86 and other archs, in order to check if the driver builds fine and
> > to enable the static analyzers to look into this code.
> 
> Ok.
> 
> [...]
> 
> > > +
> > > +	ir->rc->priv = ir;
> > > +	ir->rc->input_name = DRIVER_NAME;
> > > +	ir->rc->input_phys = DRIVER_NAME "/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;
> > 
> > I don't like very much the idea of filling it like that. From where those
> > numbers came? Could you add a define for them somewhere?
> 
> I've seen that other drivers as gpio-ir-recv and sunxi-cir assign
> those numbers to the fields of input_id but I couldn't find a
> documentation of the meaning. If the assignments are not needed I will
> drop them in the next version.
> 
> Beniamino

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

end of thread, other threads:[~2014-11-03 21:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-12 20:01 [PATCH 0/3] media: rc: add support for Amlogic Meson IR receiver Beniamino Galvani
2014-10-12 20:01 ` [PATCH 1/3] media: rc: add driver for Amlogic Meson IR remote receiver Beniamino Galvani
2014-11-03 13:14   ` Mauro Carvalho Chehab
2014-11-03 20:54     ` Beniamino Galvani
2014-11-03 21:04       ` Mauro Carvalho Chehab
2014-10-12 20:01 ` [PATCH 2/3] media: rc: meson: document device tree bindings Beniamino Galvani
2014-10-12 20:01 ` [PATCH 3/3] ARM: dts: meson: add dts nodes for IR receiver Beniamino Galvani

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