[PATCH v10 1/5] ARM: sunxi: Add documentation for sunxi consumer infrared devices

2014-06-21 Thread Alexander Bersenev
This patch adds documentation for Device-Tree bindings for sunxi IR
controller.

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 .../devicetree/bindings/media/sunxi-ir.txt |   23 
 1 files changed, 23 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt

diff --git a/Documentation/devicetree/bindings/media/sunxi-ir.txt 
b/Documentation/devicetree/bindings/media/sunxi-ir.txt
new file mode 100644
index 000..014dd8b
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/sunxi-ir.txt
@@ -0,0 +1,23 @@
+Device-Tree bindings for SUNXI IR controller found in sunXi SoC family
+
+Required properties:
+- compatible   : should be "allwinner,sun7i-a20-ir";
+- clocks   : list of clock specifiers, corresponding to
+ entries in clock-names property;
+- clock-names  : should contain "apb" and "ir" entries;
+- interrupts   : should contain IR IRQ number;
+- reg  : should contain IO map address for IR.
+
+Optional properties:
+- linux,rc-map-name : Remote control map name.
+
+Example:
+
+ir0: ir@01c21800 {
+   compatible = "allwinner,sun7i-a20-ir";
+   clocks = <_gates 6>, <_clk>;
+   clock-names = "apb", "ir";
+   interrupts = <0 5 1>;
+   reg = <0x01C21800 0x40>;
+   linux,rc-map-name = "rc-rc6-mce";
+};
-- 
1.7.1

--
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/


[PATCH v10 2/5] [media] rc: add sunxi-ir driver

2014-06-21 Thread Alexander Bersenev
This patch adds driver for sunxi IR controller.
It is based on Alexsey Shestacov's work based on the original driver
supplied by Allwinner.

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 drivers/media/rc/Kconfig |   10 ++
 drivers/media/rc/Makefile|1 +
 drivers/media/rc/sunxi-cir.c |  318 ++
 3 files changed, 329 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/rc/sunxi-cir.c

diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 8fbd377..9427fad 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -343,4 +343,14 @@ config RC_ST
 
 If you're not sure, select N here.
 
+config IR_SUNXI
+tristate "SUNXI IR remote control"
+depends on RC_CORE
+depends on ARCH_SUNXI
+---help---
+  Say Y if you want to use sunXi internal IR Controller
+
+  To compile this driver as a module, choose M here: the module will
+  be called sunxi-ir.
+
 endif #RC_DEVICES
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index f8b54ff..9ee9ee7 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -32,4 +32,5 @@ 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_SUNXI) += sunxi-cir.o
 obj-$(CONFIG_IR_IMG) += img-ir/
diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c
new file mode 100644
index 000..5971b69
--- /dev/null
+++ b/drivers/media/rc/sunxi-cir.c
@@ -0,0 +1,318 @@
+/*
+ * Driver for Allwinner sunXi IR controller
+ *
+ * Copyright (C) 2014 Alexsey Shestacov 
+ * Copyright (C) 2014 Alexander Bersenev 
+ *
+ * Based on sun5i-ir.c:
+ * Copyright (C) 2007-2012 Daniel Wang
+ * Allwinner Technology Co., 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define SUNXI_IR_DEV "sunxi-ir"
+
+/* Registers */
+/* IR Control */
+#define SUNXI_IR_CTL_REG  0x00
+/* Global Enable */
+#define REG_CTL_GENBIT(0)
+/* RX block enable */
+#define REG_CTL_RXEN   BIT(1)
+/* CIR mode */
+#define REG_CTL_MD (BIT(4) | BIT(5))
+
+/* Rx Config */
+#define SUNXI_IR_RXCTL_REG0x10
+/* Pulse Polarity Invert flag */
+#define REG_RXCTL_RPPI BIT(2)
+
+/* Rx Data */
+#define SUNXI_IR_RXFIFO_REG   0x20
+
+/* Rx Interrupt Enable */
+#define SUNXI_IR_RXINT_REG0x2C
+/* Rx FIFO Overflow */
+#define REG_RXINT_ROI_EN   BIT(0)
+/* Rx Packet End */
+#define REG_RXINT_RPEI_EN  BIT(1)
+/* Rx FIFO Data Available */
+#define REG_RXINT_RAI_EN   BIT(4)
+
+/* Rx FIFO available byte level */
+#define REG_RXINT_RAL(val)(((val) << 8) & (GENMASK(11, 8)))
+
+/* Rx Interrupt Status */
+#define SUNXI_IR_RXSTA_REG0x30
+/* RX FIFO Get Available Counter */
+#define REG_RXSTA_GET_AC(val) (((val) >> 8) & (GENMASK(5, 0)))
+/* Clear all interrupt status value */
+#define REG_RXSTA_CLEARALL0xff
+
+/* IR Sample Config */
+#define SUNXI_IR_CIR_REG  0x34
+/* CIR_REG register noise threshold */
+#define REG_CIR_NTHR(val)(((val) << 2) & (GENMASK(7, 2)))
+/* CIR_REG register idle threshold */
+#define REG_CIR_ITHR(val)(((val) << 8) & (GENMASK(15, 8)))
+
+/* Hardware supported fifo size */
+#define SUNXI_IR_FIFO_SIZE16
+/* How many messages in FIFO trigger IRQ */
+#define TRIGGER_LEVEL 8
+/* Required frequency for IR0 or IR1 clock in CIR mode */
+#define SUNXI_IR_BASE_CLK 800
+/* Frequency after IR internal divider  */
+#define SUNXI_IR_CLK  (SUNXI_IR_BASE_CLK / 64)
+/* Sample period in ns */
+#define SUNXI_IR_SAMPLE   (10ul / SUNXI_IR_CLK)
+/* Noise threshold in samples  */
+#define SUNXI_IR_RXNOISE  1
+/* Idle Threshold in samples */
+#define SUNXI_IR_RXIDLE   20
+/* Time after which device stops sending data in ms */
+#define SUNXI_IR_TIMEOUT  120
+
+struct sunxi_ir {
+   spinlock_t  ir_lock;
+   struct rc_dev   *rc;
+   void __iomem*base;
+   int irq;
+   struct clk  *clk;
+   struct clk  *apb_clk;
+   const char  *map_name;
+};
+
+static irqreturn_t sunxi_ir_irq(int irqno, void *dev_id)
+{
+   unsigned long status;
+   unsigned char dt;
+   unsigned int cnt, rc;
+   struct sunxi_ir *ir = dev_id;
+   

[PATCH v10 4/5] ARM: sunxi: Add IR controllers on A20 to dtsi

2014-06-21 Thread Alexander Bersenev
This patch adds records for two IR controllers on A20

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 arch/arm/boot/dts/sun7i-a20.dtsi |   18 ++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index 656d7d3..1782375 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -785,6 +785,24 @@
status = "disabled";
};
 
+   ir0: ir@01c21800 {
+   compatible = "allwinner,sun7i-a20-ir";
+   clocks = <_gates 6>, <_clk>;
+   clock-names = "apb", "ir";
+   interrupts = <0 5 4>;
+   reg = <0x01c21800 0x40>;
+   status = "disabled";
+   };
+
+   ir1: ir@01c21c00 {
+   compatible = "allwinner,sun7i-a20-ir";
+   clocks = <_gates 7>, <_clk>;
+   clock-names = "apb", "ir";
+   interrupts = <0 6 4>;
+   reg = <0x01c21c00 0x40>;
+   status = "disabled";
+   };
+
sid: eeprom@01c23800 {
compatible = "allwinner,sun7i-a20-sid";
reg = <0x01c23800 0x200>;
-- 
1.7.1

--
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/


[PATCH v10 5/5] ARM: sunxi: Enable IR controller on cubieboard 2 and cubietruck in dts

2014-06-21 Thread Alexander Bersenev
This patch enables two IR devices in dts:
- One IR device physically found on Cubieboard 2
- One IR device physically found on Cubietruck

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts |6 ++
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts  |6 ++
 2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts 
b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
index a5ad945..a70f0b4 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
@@ -66,6 +66,12 @@
};
};
 
+   ir0: ir@01c21800 {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins_a>;
+   status = "okay";
+   };
+
uart0: serial@01c28000 {
pinctrl-names = "default";
pinctrl-0 = <_pins_a>;
diff --git a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts 
b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
index b87fea9..96639d5 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
@@ -100,6 +100,12 @@
status = "okay";
};
 
+   ir0: ir@01c21800 {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins_a>;
+   status = "okay";
+   };
+
uart0: serial@01c28000 {
pinctrl-names = "default";
pinctrl-0 = <_pins_a>;
-- 
1.7.1

--
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/


[PATCH v10 3/5] ARM: sunxi: Add pins for IR controller on A20 to dtsi

2014-06-21 Thread Alexander Bersenev
This patch adds pins for two IR controllers on A20

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 arch/arm/boot/dts/sun7i-a20.dtsi |   14 ++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index 01e9466..656d7d3 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -738,6 +738,20 @@
allwinner,drive = <2>;
allwinner,pull = <0>;
};
+
+   ir0_pins_a: ir0@0 {
+   allwinner,pins = "PB3","PB4";
+   allwinner,function = "ir0";
+   allwinner,drive = <0>;
+   allwinner,pull = <0>;
+   };
+
+   ir1_pins_a: ir1@0 {
+   allwinner,pins = "PB22","PB23";
+   allwinner,function = "ir1";
+   allwinner,drive = <0>;
+   allwinner,pull = <0>;
+   };
};
 
timer@01c20c00 {
-- 
1.7.1

--
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/


[PATCH v10 0/5] ARM: sunxi: Add support for consumer infrared devices

2014-06-21 Thread Alexander Bersenev
This patch introduces Consumer IR(CIR) support for sunxi boards.

This is based on Alexsey Shestacov's work based on the original driver 
supplied by Allwinner.

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 

---
Changes since version 1: 
 - Fix timer memory leaks 
 - Fix race condition when driver unloads while interrupt handler is active
 - Support Cubieboard 2(need testing)

Changes since version 2:
- More reliable keydown events
- Documentation fixes
- Rename registers accurding to A20 user manual
- Remove some includes, order includes alphabetically
- Use BIT macro
- Typo fixes

Changes since version 3:
- Split the patch on smaller parts
- More documentation fixes
- Add clock-names in DT
- Use devm_clk_get function to get the clocks
- Removed gpios property from ir's DT
- Changed compatible from allwinner,sunxi-ir to allwinner,sun7i-a20-ir in DT
- Use spin_lock_irq instead spin_lock_irqsave in interrupt handler
- Add myself in the copyright ;)
- Coding style and indentation fixes

Changes since version 4:
- Try to fix indentation errors by sending patches with git send-mail

Changes since version 5:
- More indentation fixes
- Make patches pass checkpatch with --strict option
- Replaced magic numbers with defines(patch by Priit Laes)
- Fixed oops on loading(patch by Hans de Goede)

Changes since version 6:
- Removed constants from code
- Better errrors handling on loading
- Renamed sunxi-ir.c to sunxi-cir.c
- Changed description of second commit
- Order entries in dts and dtsi by register address
- Code style fixes

Changes since version 7:
- Removed a couple of blank lines in code
- Delay interrupts init until we are ready to handle them
- Increased the reported duration of each pulse by one
- Refactored defines

Changes since version 8:
- Split the DT patch to three
- Code style fixes

Changes since version 9:
- Rebase patches on 3.16-rc1

Alexander Bersenev (5):
  ARM: sunxi: Add documentation for sunxi consumer infrared devices
  [media] rc: add sunxi-ir driver
  ARM: sunxi: Add pins for IR controller on A20 to dtsi
  ARM: sunxi: Add IR controllers on A20 to dtsi
  ARM: sunxi: Enable IR controller on cubieboard 2 and cubietruck in
dts

 .../devicetree/bindings/media/sunxi-ir.txt |   23 ++
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts|6 +
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts |6 +
 arch/arm/boot/dts/sun7i-a20.dtsi   |   32 ++
 drivers/media/rc/Kconfig   |   10 +
 drivers/media/rc/Makefile  |1 +
 drivers/media/rc/sunxi-cir.c   |  318 
 7 files changed, 396 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt
 create mode 100644 drivers/media/rc/sunxi-cir.c

--
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/


[PATCH v10 3/5] ARM: sunxi: Add pins for IR controller on A20 to dtsi

2014-06-21 Thread Alexander Bersenev
This patch adds pins for two IR controllers on A20

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 arch/arm/boot/dts/sun7i-a20.dtsi |   14 ++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index 01e9466..656d7d3 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -738,6 +738,20 @@
allwinner,drive = 2;
allwinner,pull = 0;
};
+
+   ir0_pins_a: ir0@0 {
+   allwinner,pins = PB3,PB4;
+   allwinner,function = ir0;
+   allwinner,drive = 0;
+   allwinner,pull = 0;
+   };
+
+   ir1_pins_a: ir1@0 {
+   allwinner,pins = PB22,PB23;
+   allwinner,function = ir1;
+   allwinner,drive = 0;
+   allwinner,pull = 0;
+   };
};
 
timer@01c20c00 {
-- 
1.7.1

--
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/


[PATCH v10 0/5] ARM: sunxi: Add support for consumer infrared devices

2014-06-21 Thread Alexander Bersenev
This patch introduces Consumer IR(CIR) support for sunxi boards.

This is based on Alexsey Shestacov's work based on the original driver 
supplied by Allwinner.

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org

---
Changes since version 1: 
 - Fix timer memory leaks 
 - Fix race condition when driver unloads while interrupt handler is active
 - Support Cubieboard 2(need testing)

Changes since version 2:
- More reliable keydown events
- Documentation fixes
- Rename registers accurding to A20 user manual
- Remove some includes, order includes alphabetically
- Use BIT macro
- Typo fixes

Changes since version 3:
- Split the patch on smaller parts
- More documentation fixes
- Add clock-names in DT
- Use devm_clk_get function to get the clocks
- Removed gpios property from ir's DT
- Changed compatible from allwinner,sunxi-ir to allwinner,sun7i-a20-ir in DT
- Use spin_lock_irq instead spin_lock_irqsave in interrupt handler
- Add myself in the copyright ;)
- Coding style and indentation fixes

Changes since version 4:
- Try to fix indentation errors by sending patches with git send-mail

Changes since version 5:
- More indentation fixes
- Make patches pass checkpatch with --strict option
- Replaced magic numbers with defines(patch by Priit Laes)
- Fixed oops on loading(patch by Hans de Goede)

Changes since version 6:
- Removed constants from code
- Better errrors handling on loading
- Renamed sunxi-ir.c to sunxi-cir.c
- Changed description of second commit
- Order entries in dts and dtsi by register address
- Code style fixes

Changes since version 7:
- Removed a couple of blank lines in code
- Delay interrupts init until we are ready to handle them
- Increased the reported duration of each pulse by one
- Refactored defines

Changes since version 8:
- Split the DT patch to three
- Code style fixes

Changes since version 9:
- Rebase patches on 3.16-rc1

Alexander Bersenev (5):
  ARM: sunxi: Add documentation for sunxi consumer infrared devices
  [media] rc: add sunxi-ir driver
  ARM: sunxi: Add pins for IR controller on A20 to dtsi
  ARM: sunxi: Add IR controllers on A20 to dtsi
  ARM: sunxi: Enable IR controller on cubieboard 2 and cubietruck in
dts

 .../devicetree/bindings/media/sunxi-ir.txt |   23 ++
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts|6 +
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts |6 +
 arch/arm/boot/dts/sun7i-a20.dtsi   |   32 ++
 drivers/media/rc/Kconfig   |   10 +
 drivers/media/rc/Makefile  |1 +
 drivers/media/rc/sunxi-cir.c   |  318 
 7 files changed, 396 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt
 create mode 100644 drivers/media/rc/sunxi-cir.c

--
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/


[PATCH v10 4/5] ARM: sunxi: Add IR controllers on A20 to dtsi

2014-06-21 Thread Alexander Bersenev
This patch adds records for two IR controllers on A20

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 arch/arm/boot/dts/sun7i-a20.dtsi |   18 ++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index 656d7d3..1782375 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -785,6 +785,24 @@
status = disabled;
};
 
+   ir0: ir@01c21800 {
+   compatible = allwinner,sun7i-a20-ir;
+   clocks = apb0_gates 6, ir0_clk;
+   clock-names = apb, ir;
+   interrupts = 0 5 4;
+   reg = 0x01c21800 0x40;
+   status = disabled;
+   };
+
+   ir1: ir@01c21c00 {
+   compatible = allwinner,sun7i-a20-ir;
+   clocks = apb0_gates 7, ir1_clk;
+   clock-names = apb, ir;
+   interrupts = 0 6 4;
+   reg = 0x01c21c00 0x40;
+   status = disabled;
+   };
+
sid: eeprom@01c23800 {
compatible = allwinner,sun7i-a20-sid;
reg = 0x01c23800 0x200;
-- 
1.7.1

--
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/


[PATCH v10 5/5] ARM: sunxi: Enable IR controller on cubieboard 2 and cubietruck in dts

2014-06-21 Thread Alexander Bersenev
This patch enables two IR devices in dts:
- One IR device physically found on Cubieboard 2
- One IR device physically found on Cubietruck

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts |6 ++
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts  |6 ++
 2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts 
b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
index a5ad945..a70f0b4 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
@@ -66,6 +66,12 @@
};
};
 
+   ir0: ir@01c21800 {
+   pinctrl-names = default;
+   pinctrl-0 = ir0_pins_a;
+   status = okay;
+   };
+
uart0: serial@01c28000 {
pinctrl-names = default;
pinctrl-0 = uart0_pins_a;
diff --git a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts 
b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
index b87fea9..96639d5 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
@@ -100,6 +100,12 @@
status = okay;
};
 
+   ir0: ir@01c21800 {
+   pinctrl-names = default;
+   pinctrl-0 = ir0_pins_a;
+   status = okay;
+   };
+
uart0: serial@01c28000 {
pinctrl-names = default;
pinctrl-0 = uart0_pins_a;
-- 
1.7.1

--
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/


[PATCH v10 2/5] [media] rc: add sunxi-ir driver

2014-06-21 Thread Alexander Bersenev
This patch adds driver for sunxi IR controller.
It is based on Alexsey Shestacov's work based on the original driver
supplied by Allwinner.

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 drivers/media/rc/Kconfig |   10 ++
 drivers/media/rc/Makefile|1 +
 drivers/media/rc/sunxi-cir.c |  318 ++
 3 files changed, 329 insertions(+), 0 deletions(-)
 create mode 100644 drivers/media/rc/sunxi-cir.c

diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 8fbd377..9427fad 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -343,4 +343,14 @@ config RC_ST
 
 If you're not sure, select N here.
 
+config IR_SUNXI
+tristate SUNXI IR remote control
+depends on RC_CORE
+depends on ARCH_SUNXI
+---help---
+  Say Y if you want to use sunXi internal IR Controller
+
+  To compile this driver as a module, choose M here: the module will
+  be called sunxi-ir.
+
 endif #RC_DEVICES
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index f8b54ff..9ee9ee7 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -32,4 +32,5 @@ 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_SUNXI) += sunxi-cir.o
 obj-$(CONFIG_IR_IMG) += img-ir/
diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c
new file mode 100644
index 000..5971b69
--- /dev/null
+++ b/drivers/media/rc/sunxi-cir.c
@@ -0,0 +1,318 @@
+/*
+ * Driver for Allwinner sunXi IR controller
+ *
+ * Copyright (C) 2014 Alexsey Shestacov wingr...@linux-sunxi.org
+ * Copyright (C) 2014 Alexander Bersenev b...@hackerdom.ru
+ *
+ * Based on sun5i-ir.c:
+ * Copyright (C) 2007-2012 Daniel Wang
+ * Allwinner Technology Co., Ltd. www.allwinnertech.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/clk.h
+#include linux/interrupt.h
+#include linux/module.h
+#include linux/of_platform.h
+#include media/rc-core.h
+
+#define SUNXI_IR_DEV sunxi-ir
+
+/* Registers */
+/* IR Control */
+#define SUNXI_IR_CTL_REG  0x00
+/* Global Enable */
+#define REG_CTL_GENBIT(0)
+/* RX block enable */
+#define REG_CTL_RXEN   BIT(1)
+/* CIR mode */
+#define REG_CTL_MD (BIT(4) | BIT(5))
+
+/* Rx Config */
+#define SUNXI_IR_RXCTL_REG0x10
+/* Pulse Polarity Invert flag */
+#define REG_RXCTL_RPPI BIT(2)
+
+/* Rx Data */
+#define SUNXI_IR_RXFIFO_REG   0x20
+
+/* Rx Interrupt Enable */
+#define SUNXI_IR_RXINT_REG0x2C
+/* Rx FIFO Overflow */
+#define REG_RXINT_ROI_EN   BIT(0)
+/* Rx Packet End */
+#define REG_RXINT_RPEI_EN  BIT(1)
+/* Rx FIFO Data Available */
+#define REG_RXINT_RAI_EN   BIT(4)
+
+/* Rx FIFO available byte level */
+#define REG_RXINT_RAL(val)(((val)  8)  (GENMASK(11, 8)))
+
+/* Rx Interrupt Status */
+#define SUNXI_IR_RXSTA_REG0x30
+/* RX FIFO Get Available Counter */
+#define REG_RXSTA_GET_AC(val) (((val)  8)  (GENMASK(5, 0)))
+/* Clear all interrupt status value */
+#define REG_RXSTA_CLEARALL0xff
+
+/* IR Sample Config */
+#define SUNXI_IR_CIR_REG  0x34
+/* CIR_REG register noise threshold */
+#define REG_CIR_NTHR(val)(((val)  2)  (GENMASK(7, 2)))
+/* CIR_REG register idle threshold */
+#define REG_CIR_ITHR(val)(((val)  8)  (GENMASK(15, 8)))
+
+/* Hardware supported fifo size */
+#define SUNXI_IR_FIFO_SIZE16
+/* How many messages in FIFO trigger IRQ */
+#define TRIGGER_LEVEL 8
+/* Required frequency for IR0 or IR1 clock in CIR mode */
+#define SUNXI_IR_BASE_CLK 800
+/* Frequency after IR internal divider  */
+#define SUNXI_IR_CLK  (SUNXI_IR_BASE_CLK / 64)
+/* Sample period in ns */
+#define SUNXI_IR_SAMPLE   (10ul / SUNXI_IR_CLK)
+/* Noise threshold in samples  */
+#define SUNXI_IR_RXNOISE  1
+/* Idle Threshold in samples */
+#define SUNXI_IR_RXIDLE   20
+/* Time after which device stops sending data in ms */
+#define SUNXI_IR_TIMEOUT  120
+
+struct sunxi_ir {
+   spinlock_t  ir_lock;
+   struct rc_dev   *rc;
+   void __iomem*base;
+   int irq;
+   struct clk  *clk;
+   struct clk  *apb_clk;
+   const char  *map_name;
+};
+
+static irqreturn_t sunxi_ir_irq(int irqno, void *dev_id)
+{
+   unsigned long status

[PATCH v10 1/5] ARM: sunxi: Add documentation for sunxi consumer infrared devices

2014-06-21 Thread Alexander Bersenev
This patch adds documentation for Device-Tree bindings for sunxi IR
controller.

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 .../devicetree/bindings/media/sunxi-ir.txt |   23 
 1 files changed, 23 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt

diff --git a/Documentation/devicetree/bindings/media/sunxi-ir.txt 
b/Documentation/devicetree/bindings/media/sunxi-ir.txt
new file mode 100644
index 000..014dd8b
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/sunxi-ir.txt
@@ -0,0 +1,23 @@
+Device-Tree bindings for SUNXI IR controller found in sunXi SoC family
+
+Required properties:
+- compatible   : should be allwinner,sun7i-a20-ir;
+- clocks   : list of clock specifiers, corresponding to
+ entries in clock-names property;
+- clock-names  : should contain apb and ir entries;
+- interrupts   : should contain IR IRQ number;
+- reg  : should contain IO map address for IR.
+
+Optional properties:
+- linux,rc-map-name : Remote control map name.
+
+Example:
+
+ir0: ir@01c21800 {
+   compatible = allwinner,sun7i-a20-ir;
+   clocks = apb0_gates 6, ir0_clk;
+   clock-names = apb, ir;
+   interrupts = 0 5 1;
+   reg = 0x01C21800 0x40;
+   linux,rc-map-name = rc-rc6-mce;
+};
-- 
1.7.1

--
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/


[PATCH v9 3/5] ARM: sunxi: Add pins for IR controller on A20 to dtsi

2014-06-08 Thread Alexander Bersenev
This patch adds pins for two IR controllers on A20

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 arch/arm/boot/dts/sun7i-a20.dtsi | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index 0ae2b77..c057c3e 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -724,6 +724,20 @@
allwinner,drive = <2>;
allwinner,pull = <0>;
};
+
+   ir0_pins_a: ir0@0 {
+   allwinner,pins = "PB3","PB4";
+   allwinner,function = "ir0";
+   allwinner,drive = <0>;
+   allwinner,pull = <0>;
+   };
+
+   ir1_pins_a: ir1@0 {
+   allwinner,pins = "PB22","PB23";
+   allwinner,function = "ir1";
+   allwinner,drive = <0>;
+   allwinner,pull = <0>;
+   };
};
 
timer@01c20c00 {
-- 
1.9.3

--
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/


[PATCH v9 5/5] ARM: sunxi: Enable IR controller on cubieboard 2 and cubietruck in dts

2014-06-08 Thread Alexander Bersenev
This patch enables two IR devices in dts:
- One IR device physically found on Cubieboard 2
- One IR device physically found on Cubietruck

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts | 6 ++
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts  | 6 ++
 2 files changed, 12 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts 
b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
index feeff64..b44d61b 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
@@ -65,6 +65,12 @@
};
};
 
+   ir0: ir@01c21800 {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins_a>;
+   status = "okay";
+   };
+
uart0: serial@01c28000 {
pinctrl-names = "default";
pinctrl-0 = <_pins_a>;
diff --git a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts 
b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
index e288562..5f5c31d 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
@@ -121,6 +121,12 @@
};
};
 
+   ir0: ir@01c21800 {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins_a>;
+   status = "okay";
+   };
+
uart0: serial@01c28000 {
pinctrl-names = "default";
pinctrl-0 = <_pins_a>;
-- 
1.9.3

--
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/


[PATCH v9 4/5] ARM: sunxi: Add IR controllers on A20 to dtsi

2014-06-08 Thread Alexander Bersenev
This patch adds records for two IR controllers on A20

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 arch/arm/boot/dts/sun7i-a20.dtsi | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index c057c3e..fe1f8ff 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -763,6 +763,24 @@
interrupts = <0 24 4>;
};
 
+   ir0: ir@01c21800 {
+   compatible = "allwinner,sun7i-a20-ir";
+   clocks = <_gates 6>, <_clk>;
+   clock-names = "apb", "ir";
+   interrupts = <0 5 4>;
+   reg = <0x01c21800 0x40>;
+   status = "disabled";
+   };
+
+   ir1: ir@01c21c00 {
+   compatible = "allwinner,sun7i-a20-ir";
+   clocks = <_gates 7>, <_clk>;
+   clock-names = "apb", "ir";
+   interrupts = <0 6 4>;
+   reg = <0x01c21c00 0x40>;
+   status = "disabled";
+   };
+
lradc: lradc@01c22800 {
compatible = "allwinner,sun4i-lradc-keys";
reg = <0x01c22800 0x100>;
-- 
1.9.3

--
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/


[PATCH v9 2/5] [media] rc: add sunxi-ir driver

2014-06-08 Thread Alexander Bersenev
This patch adds driver for sunxi IR controller.
It is based on Alexsey Shestacov's work based on the original driver
supplied by Allwinner.

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 drivers/media/rc/Kconfig |  10 ++
 drivers/media/rc/Makefile|   1 +
 drivers/media/rc/sunxi-cir.c | 318 +++
 3 files changed, 329 insertions(+)
 create mode 100644 drivers/media/rc/sunxi-cir.c

diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 8fbd377..9427fad 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -343,4 +343,14 @@ config RC_ST
 
 If you're not sure, select N here.
 
+config IR_SUNXI
+tristate "SUNXI IR remote control"
+depends on RC_CORE
+depends on ARCH_SUNXI
+---help---
+  Say Y if you want to use sunXi internal IR Controller
+
+  To compile this driver as a module, choose M here: the module will
+  be called sunxi-ir.
+
 endif #RC_DEVICES
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index f8b54ff..9ee9ee7 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -32,4 +32,5 @@ 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_SUNXI) += sunxi-cir.o
 obj-$(CONFIG_IR_IMG) += img-ir/
diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c
new file mode 100644
index 000..5971b69
--- /dev/null
+++ b/drivers/media/rc/sunxi-cir.c
@@ -0,0 +1,318 @@
+/*
+ * Driver for Allwinner sunXi IR controller
+ *
+ * Copyright (C) 2014 Alexsey Shestacov 
+ * Copyright (C) 2014 Alexander Bersenev 
+ *
+ * Based on sun5i-ir.c:
+ * Copyright (C) 2007-2012 Daniel Wang
+ * Allwinner Technology Co., 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define SUNXI_IR_DEV "sunxi-ir"
+
+/* Registers */
+/* IR Control */
+#define SUNXI_IR_CTL_REG  0x00
+/* Global Enable */
+#define REG_CTL_GENBIT(0)
+/* RX block enable */
+#define REG_CTL_RXEN   BIT(1)
+/* CIR mode */
+#define REG_CTL_MD (BIT(4) | BIT(5))
+
+/* Rx Config */
+#define SUNXI_IR_RXCTL_REG0x10
+/* Pulse Polarity Invert flag */
+#define REG_RXCTL_RPPI BIT(2)
+
+/* Rx Data */
+#define SUNXI_IR_RXFIFO_REG   0x20
+
+/* Rx Interrupt Enable */
+#define SUNXI_IR_RXINT_REG0x2C
+/* Rx FIFO Overflow */
+#define REG_RXINT_ROI_EN   BIT(0)
+/* Rx Packet End */
+#define REG_RXINT_RPEI_EN  BIT(1)
+/* Rx FIFO Data Available */
+#define REG_RXINT_RAI_EN   BIT(4)
+
+/* Rx FIFO available byte level */
+#define REG_RXINT_RAL(val)(((val) << 8) & (GENMASK(11, 8)))
+
+/* Rx Interrupt Status */
+#define SUNXI_IR_RXSTA_REG0x30
+/* RX FIFO Get Available Counter */
+#define REG_RXSTA_GET_AC(val) (((val) >> 8) & (GENMASK(5, 0)))
+/* Clear all interrupt status value */
+#define REG_RXSTA_CLEARALL0xff
+
+/* IR Sample Config */
+#define SUNXI_IR_CIR_REG  0x34
+/* CIR_REG register noise threshold */
+#define REG_CIR_NTHR(val)(((val) << 2) & (GENMASK(7, 2)))
+/* CIR_REG register idle threshold */
+#define REG_CIR_ITHR(val)(((val) << 8) & (GENMASK(15, 8)))
+
+/* Hardware supported fifo size */
+#define SUNXI_IR_FIFO_SIZE16
+/* How many messages in FIFO trigger IRQ */
+#define TRIGGER_LEVEL 8
+/* Required frequency for IR0 or IR1 clock in CIR mode */
+#define SUNXI_IR_BASE_CLK 800
+/* Frequency after IR internal divider  */
+#define SUNXI_IR_CLK  (SUNXI_IR_BASE_CLK / 64)
+/* Sample period in ns */
+#define SUNXI_IR_SAMPLE   (10ul / SUNXI_IR_CLK)
+/* Noise threshold in samples  */
+#define SUNXI_IR_RXNOISE  1
+/* Idle Threshold in samples */
+#define SUNXI_IR_RXIDLE   20
+/* Time after which device stops sending data in ms */
+#define SUNXI_IR_TIMEOUT  120
+
+struct sunxi_ir {
+   spinlock_t  ir_lock;
+   struct rc_dev   *rc;
+   void __iomem*base;
+   int irq;
+   struct clk  *clk;
+   struct clk  *apb_clk;
+   const char  *map_name;
+};
+
+static irqreturn_t sunxi_ir_irq(int irqno, void *dev_id)
+{
+   unsigned long status;
+   unsigned char dt;
+   unsigned int cnt, rc;
+   struct sunxi_ir *ir = dev_id;
+   DEFINE_IR_RAW_E

[PATCH v9 0/5] ARM: sunxi: Add support for consumer infrared devices

2014-06-08 Thread Alexander Bersenev
This patch introduces Consumer IR(CIR) support for sunxi boards.

This is based on Alexsey Shestacov's work based on the original driver 
supplied by Allwinner.

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 

---
Changes since version 1: 
 - Fix timer memory leaks 
 - Fix race condition when driver unloads while interrupt handler is active
 - Support Cubieboard 2(need testing)

Changes since version 2:
- More reliable keydown events
- Documentation fixes
- Rename registers accurding to A20 user manual
- Remove some includes, order includes alphabetically
- Use BIT macro
- Typo fixes

Changes since version 3:
- Split the patch on smaller parts
- More documentation fixes
- Add clock-names in DT
- Use devm_clk_get function to get the clocks
- Removed gpios property from ir's DT
- Changed compatible from allwinner,sunxi-ir to allwinner,sun7i-a20-ir in DT
- Use spin_lock_irq instead spin_lock_irqsave in interrupt handler
- Add myself in the copyright ;)
- Coding style and indentation fixes

Changes since version 4:
- Try to fix indentation errors by sending patches with git send-mail

Changes since version 5:
- More indentation fixes
- Make patches pass checkpatch with --strict option
- Replaced magic numbers with defines(patch by Priit Laes)
- Fixed oops on loading(patch by Hans de Goede)

Changes since version 6:
- Removed constants from code
- Better errrors handling on loading
- Renamed sunxi-ir.c to sunxi-cir.c
- Changed description of second commit
- Order entries in dts and dtsi by register address
- Code style fixes

Changes since version 7:
- Removed a couple of blank lines in code
- Delay interrupts init until we are ready to handle them
- Increased the reported duration of each pulse by one
- Refactored defines

Changes since version 8:
- Split the DT patch to three
- Code style fixes

Alexander Bersenev (5):
  ARM: sunxi: Add documentation for sunxi consumer infrared devices
  [media] rc: add sunxi-ir driver
  ARM: sunxi: Add pins for IR controller on A20 to dtsi
  ARM: sunxi: Add IR controllers on A20 to dtsi
  ARM: sunxi: Enable IR controller on cubieboard 2 and cubietruck in dts

 .../devicetree/bindings/media/sunxi-ir.txt |  23 ++
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts|   6 +
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts |   6 +
 arch/arm/boot/dts/sun7i-a20.dtsi   |  32 +++
 drivers/media/rc/Kconfig   |  10 +
 drivers/media/rc/Makefile  |   1 +
 drivers/media/rc/sunxi-cir.c   | 318 +
 7 files changed, 396 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt
 create mode 100644 drivers/media/rc/sunxi-cir.c

-- 
1.9.3

--
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/


[PATCH v9 1/5] ARM: sunxi: Add documentation for sunxi consumer infrared devices

2014-06-08 Thread Alexander Bersenev
This patch adds documentation for Device-Tree bindings for sunxi IR
controller.

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 .../devicetree/bindings/media/sunxi-ir.txt | 23 ++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt

diff --git a/Documentation/devicetree/bindings/media/sunxi-ir.txt 
b/Documentation/devicetree/bindings/media/sunxi-ir.txt
new file mode 100644
index 000..014dd8b
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/sunxi-ir.txt
@@ -0,0 +1,23 @@
+Device-Tree bindings for SUNXI IR controller found in sunXi SoC family
+
+Required properties:
+- compatible   : should be "allwinner,sun7i-a20-ir";
+- clocks   : list of clock specifiers, corresponding to
+ entries in clock-names property;
+- clock-names  : should contain "apb" and "ir" entries;
+- interrupts   : should contain IR IRQ number;
+- reg  : should contain IO map address for IR.
+
+Optional properties:
+- linux,rc-map-name : Remote control map name.
+
+Example:
+
+ir0: ir@01c21800 {
+   compatible = "allwinner,sun7i-a20-ir";
+   clocks = <_gates 6>, <_clk>;
+   clock-names = "apb", "ir";
+   interrupts = <0 5 1>;
+   reg = <0x01C21800 0x40>;
+   linux,rc-map-name = "rc-rc6-mce";
+};
-- 
1.9.3

--
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/


[PATCH v9 0/5] ARM: sunxi: Add support for consumer infrared devices

2014-06-08 Thread Alexander Bersenev
This patch introduces Consumer IR(CIR) support for sunxi boards.

This is based on Alexsey Shestacov's work based on the original driver 
supplied by Allwinner.

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org

---
Changes since version 1: 
 - Fix timer memory leaks 
 - Fix race condition when driver unloads while interrupt handler is active
 - Support Cubieboard 2(need testing)

Changes since version 2:
- More reliable keydown events
- Documentation fixes
- Rename registers accurding to A20 user manual
- Remove some includes, order includes alphabetically
- Use BIT macro
- Typo fixes

Changes since version 3:
- Split the patch on smaller parts
- More documentation fixes
- Add clock-names in DT
- Use devm_clk_get function to get the clocks
- Removed gpios property from ir's DT
- Changed compatible from allwinner,sunxi-ir to allwinner,sun7i-a20-ir in DT
- Use spin_lock_irq instead spin_lock_irqsave in interrupt handler
- Add myself in the copyright ;)
- Coding style and indentation fixes

Changes since version 4:
- Try to fix indentation errors by sending patches with git send-mail

Changes since version 5:
- More indentation fixes
- Make patches pass checkpatch with --strict option
- Replaced magic numbers with defines(patch by Priit Laes)
- Fixed oops on loading(patch by Hans de Goede)

Changes since version 6:
- Removed constants from code
- Better errrors handling on loading
- Renamed sunxi-ir.c to sunxi-cir.c
- Changed description of second commit
- Order entries in dts and dtsi by register address
- Code style fixes

Changes since version 7:
- Removed a couple of blank lines in code
- Delay interrupts init until we are ready to handle them
- Increased the reported duration of each pulse by one
- Refactored defines

Changes since version 8:
- Split the DT patch to three
- Code style fixes

Alexander Bersenev (5):
  ARM: sunxi: Add documentation for sunxi consumer infrared devices
  [media] rc: add sunxi-ir driver
  ARM: sunxi: Add pins for IR controller on A20 to dtsi
  ARM: sunxi: Add IR controllers on A20 to dtsi
  ARM: sunxi: Enable IR controller on cubieboard 2 and cubietruck in dts

 .../devicetree/bindings/media/sunxi-ir.txt |  23 ++
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts|   6 +
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts |   6 +
 arch/arm/boot/dts/sun7i-a20.dtsi   |  32 +++
 drivers/media/rc/Kconfig   |  10 +
 drivers/media/rc/Makefile  |   1 +
 drivers/media/rc/sunxi-cir.c   | 318 +
 7 files changed, 396 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt
 create mode 100644 drivers/media/rc/sunxi-cir.c

-- 
1.9.3

--
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/


[PATCH v9 1/5] ARM: sunxi: Add documentation for sunxi consumer infrared devices

2014-06-08 Thread Alexander Bersenev
This patch adds documentation for Device-Tree bindings for sunxi IR
controller.

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 .../devicetree/bindings/media/sunxi-ir.txt | 23 ++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt

diff --git a/Documentation/devicetree/bindings/media/sunxi-ir.txt 
b/Documentation/devicetree/bindings/media/sunxi-ir.txt
new file mode 100644
index 000..014dd8b
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/sunxi-ir.txt
@@ -0,0 +1,23 @@
+Device-Tree bindings for SUNXI IR controller found in sunXi SoC family
+
+Required properties:
+- compatible   : should be allwinner,sun7i-a20-ir;
+- clocks   : list of clock specifiers, corresponding to
+ entries in clock-names property;
+- clock-names  : should contain apb and ir entries;
+- interrupts   : should contain IR IRQ number;
+- reg  : should contain IO map address for IR.
+
+Optional properties:
+- linux,rc-map-name : Remote control map name.
+
+Example:
+
+ir0: ir@01c21800 {
+   compatible = allwinner,sun7i-a20-ir;
+   clocks = apb0_gates 6, ir0_clk;
+   clock-names = apb, ir;
+   interrupts = 0 5 1;
+   reg = 0x01C21800 0x40;
+   linux,rc-map-name = rc-rc6-mce;
+};
-- 
1.9.3

--
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/


[PATCH v9 2/5] [media] rc: add sunxi-ir driver

2014-06-08 Thread Alexander Bersenev
This patch adds driver for sunxi IR controller.
It is based on Alexsey Shestacov's work based on the original driver
supplied by Allwinner.

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 drivers/media/rc/Kconfig |  10 ++
 drivers/media/rc/Makefile|   1 +
 drivers/media/rc/sunxi-cir.c | 318 +++
 3 files changed, 329 insertions(+)
 create mode 100644 drivers/media/rc/sunxi-cir.c

diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 8fbd377..9427fad 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -343,4 +343,14 @@ config RC_ST
 
 If you're not sure, select N here.
 
+config IR_SUNXI
+tristate SUNXI IR remote control
+depends on RC_CORE
+depends on ARCH_SUNXI
+---help---
+  Say Y if you want to use sunXi internal IR Controller
+
+  To compile this driver as a module, choose M here: the module will
+  be called sunxi-ir.
+
 endif #RC_DEVICES
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index f8b54ff..9ee9ee7 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -32,4 +32,5 @@ 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_SUNXI) += sunxi-cir.o
 obj-$(CONFIG_IR_IMG) += img-ir/
diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c
new file mode 100644
index 000..5971b69
--- /dev/null
+++ b/drivers/media/rc/sunxi-cir.c
@@ -0,0 +1,318 @@
+/*
+ * Driver for Allwinner sunXi IR controller
+ *
+ * Copyright (C) 2014 Alexsey Shestacov wingr...@linux-sunxi.org
+ * Copyright (C) 2014 Alexander Bersenev b...@hackerdom.ru
+ *
+ * Based on sun5i-ir.c:
+ * Copyright (C) 2007-2012 Daniel Wang
+ * Allwinner Technology Co., Ltd. www.allwinnertech.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/clk.h
+#include linux/interrupt.h
+#include linux/module.h
+#include linux/of_platform.h
+#include media/rc-core.h
+
+#define SUNXI_IR_DEV sunxi-ir
+
+/* Registers */
+/* IR Control */
+#define SUNXI_IR_CTL_REG  0x00
+/* Global Enable */
+#define REG_CTL_GENBIT(0)
+/* RX block enable */
+#define REG_CTL_RXEN   BIT(1)
+/* CIR mode */
+#define REG_CTL_MD (BIT(4) | BIT(5))
+
+/* Rx Config */
+#define SUNXI_IR_RXCTL_REG0x10
+/* Pulse Polarity Invert flag */
+#define REG_RXCTL_RPPI BIT(2)
+
+/* Rx Data */
+#define SUNXI_IR_RXFIFO_REG   0x20
+
+/* Rx Interrupt Enable */
+#define SUNXI_IR_RXINT_REG0x2C
+/* Rx FIFO Overflow */
+#define REG_RXINT_ROI_EN   BIT(0)
+/* Rx Packet End */
+#define REG_RXINT_RPEI_EN  BIT(1)
+/* Rx FIFO Data Available */
+#define REG_RXINT_RAI_EN   BIT(4)
+
+/* Rx FIFO available byte level */
+#define REG_RXINT_RAL(val)(((val)  8)  (GENMASK(11, 8)))
+
+/* Rx Interrupt Status */
+#define SUNXI_IR_RXSTA_REG0x30
+/* RX FIFO Get Available Counter */
+#define REG_RXSTA_GET_AC(val) (((val)  8)  (GENMASK(5, 0)))
+/* Clear all interrupt status value */
+#define REG_RXSTA_CLEARALL0xff
+
+/* IR Sample Config */
+#define SUNXI_IR_CIR_REG  0x34
+/* CIR_REG register noise threshold */
+#define REG_CIR_NTHR(val)(((val)  2)  (GENMASK(7, 2)))
+/* CIR_REG register idle threshold */
+#define REG_CIR_ITHR(val)(((val)  8)  (GENMASK(15, 8)))
+
+/* Hardware supported fifo size */
+#define SUNXI_IR_FIFO_SIZE16
+/* How many messages in FIFO trigger IRQ */
+#define TRIGGER_LEVEL 8
+/* Required frequency for IR0 or IR1 clock in CIR mode */
+#define SUNXI_IR_BASE_CLK 800
+/* Frequency after IR internal divider  */
+#define SUNXI_IR_CLK  (SUNXI_IR_BASE_CLK / 64)
+/* Sample period in ns */
+#define SUNXI_IR_SAMPLE   (10ul / SUNXI_IR_CLK)
+/* Noise threshold in samples  */
+#define SUNXI_IR_RXNOISE  1
+/* Idle Threshold in samples */
+#define SUNXI_IR_RXIDLE   20
+/* Time after which device stops sending data in ms */
+#define SUNXI_IR_TIMEOUT  120
+
+struct sunxi_ir {
+   spinlock_t  ir_lock;
+   struct rc_dev   *rc;
+   void __iomem*base;
+   int irq;
+   struct clk  *clk;
+   struct clk  *apb_clk;
+   const char  *map_name;
+};
+
+static irqreturn_t sunxi_ir_irq(int irqno, void *dev_id)
+{
+   unsigned long status;
+   unsigned

[PATCH v9 3/5] ARM: sunxi: Add pins for IR controller on A20 to dtsi

2014-06-08 Thread Alexander Bersenev
This patch adds pins for two IR controllers on A20

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 arch/arm/boot/dts/sun7i-a20.dtsi | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index 0ae2b77..c057c3e 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -724,6 +724,20 @@
allwinner,drive = 2;
allwinner,pull = 0;
};
+
+   ir0_pins_a: ir0@0 {
+   allwinner,pins = PB3,PB4;
+   allwinner,function = ir0;
+   allwinner,drive = 0;
+   allwinner,pull = 0;
+   };
+
+   ir1_pins_a: ir1@0 {
+   allwinner,pins = PB22,PB23;
+   allwinner,function = ir1;
+   allwinner,drive = 0;
+   allwinner,pull = 0;
+   };
};
 
timer@01c20c00 {
-- 
1.9.3

--
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/


[PATCH v9 5/5] ARM: sunxi: Enable IR controller on cubieboard 2 and cubietruck in dts

2014-06-08 Thread Alexander Bersenev
This patch enables two IR devices in dts:
- One IR device physically found on Cubieboard 2
- One IR device physically found on Cubietruck

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts | 6 ++
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts  | 6 ++
 2 files changed, 12 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts 
b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
index feeff64..b44d61b 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
@@ -65,6 +65,12 @@
};
};
 
+   ir0: ir@01c21800 {
+   pinctrl-names = default;
+   pinctrl-0 = ir0_pins_a;
+   status = okay;
+   };
+
uart0: serial@01c28000 {
pinctrl-names = default;
pinctrl-0 = uart0_pins_a;
diff --git a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts 
b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
index e288562..5f5c31d 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
@@ -121,6 +121,12 @@
};
};
 
+   ir0: ir@01c21800 {
+   pinctrl-names = default;
+   pinctrl-0 = ir0_pins_a;
+   status = okay;
+   };
+
uart0: serial@01c28000 {
pinctrl-names = default;
pinctrl-0 = uart0_pins_a;
-- 
1.9.3

--
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/


[PATCH v9 4/5] ARM: sunxi: Add IR controllers on A20 to dtsi

2014-06-08 Thread Alexander Bersenev
This patch adds records for two IR controllers on A20

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 arch/arm/boot/dts/sun7i-a20.dtsi | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index c057c3e..fe1f8ff 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -763,6 +763,24 @@
interrupts = 0 24 4;
};
 
+   ir0: ir@01c21800 {
+   compatible = allwinner,sun7i-a20-ir;
+   clocks = apb0_gates 6, ir0_clk;
+   clock-names = apb, ir;
+   interrupts = 0 5 4;
+   reg = 0x01c21800 0x40;
+   status = disabled;
+   };
+
+   ir1: ir@01c21c00 {
+   compatible = allwinner,sun7i-a20-ir;
+   clocks = apb0_gates 7, ir1_clk;
+   clock-names = apb, ir;
+   interrupts = 0 6 4;
+   reg = 0x01c21c00 0x40;
+   status = disabled;
+   };
+
lradc: lradc@01c22800 {
compatible = allwinner,sun4i-lradc-keys;
reg = 0x01c22800 0x100;
-- 
1.9.3

--
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/


[PATCH v8 1/3] ARM: sunxi: Add documentation for sunxi consumer infrared devices

2014-05-25 Thread Alexander Bersenev
This patch adds documentation for Device-Tree bindings for sunxi IR
controller.

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 .../devicetree/bindings/media/sunxi-ir.txt | 23 ++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt

diff --git a/Documentation/devicetree/bindings/media/sunxi-ir.txt 
b/Documentation/devicetree/bindings/media/sunxi-ir.txt
new file mode 100644
index 000..014dd8b
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/sunxi-ir.txt
@@ -0,0 +1,23 @@
+Device-Tree bindings for SUNXI IR controller found in sunXi SoC family
+
+Required properties:
+- compatible   : should be "allwinner,sun7i-a20-ir";
+- clocks   : list of clock specifiers, corresponding to
+ entries in clock-names property;
+- clock-names  : should contain "apb" and "ir" entries;
+- interrupts   : should contain IR IRQ number;
+- reg  : should contain IO map address for IR.
+
+Optional properties:
+- linux,rc-map-name : Remote control map name.
+
+Example:
+
+ir0: ir@01c21800 {
+   compatible = "allwinner,sun7i-a20-ir";
+   clocks = <_gates 6>, <_clk>;
+   clock-names = "apb", "ir";
+   interrupts = <0 5 1>;
+   reg = <0x01C21800 0x40>;
+   linux,rc-map-name = "rc-rc6-mce";
+};
-- 
1.9.3

--
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/


[PATCH v8 2/3] [media] rc: add sunxi-ir driver

2014-05-25 Thread Alexander Bersenev
This patch adds driver for sunxi IR controller.
It is based on Alexsey Shestacov's work based on the original driver
supplied by Allwinner.

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 drivers/media/rc/Kconfig |  10 ++
 drivers/media/rc/Makefile|   1 +
 drivers/media/rc/sunxi-cir.c | 313 +++
 3 files changed, 324 insertions(+)
 create mode 100644 drivers/media/rc/sunxi-cir.c

diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 8fbd377..9427fad 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -343,4 +343,14 @@ config RC_ST
 
 If you're not sure, select N here.
 
+config IR_SUNXI
+tristate "SUNXI IR remote control"
+depends on RC_CORE
+depends on ARCH_SUNXI
+---help---
+  Say Y if you want to use sunXi internal IR Controller
+
+  To compile this driver as a module, choose M here: the module will
+  be called sunxi-ir.
+
 endif #RC_DEVICES
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index f8b54ff..9ee9ee7 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -32,4 +32,5 @@ 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_SUNXI) += sunxi-cir.o
 obj-$(CONFIG_IR_IMG) += img-ir/
diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c
new file mode 100644
index 000..245d8dc
--- /dev/null
+++ b/drivers/media/rc/sunxi-cir.c
@@ -0,0 +1,313 @@
+/*
+ * Driver for Allwinner sunXi IR controller
+ *
+ * Copyright (C) 2014 Alexsey Shestacov 
+ * Copyright (C) 2014 Alexander Bersenev 
+ *
+ * Based on sun5i-ir.c:
+ * Copyright (C) 2007-2012 Daniel Wang
+ * Allwinner Technology Co., 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define SUNXI_IR_DEV "sunxi-ir"
+
+/* Registers */
+/* IR Control */
+#define SUNXI_IR_CTL_REG  0x00
+#define REG_CTL_GEN   BIT(0) /* Global Enable */
+#define REG_CTL_RXEN  BIT(1) /* RX block enable */
+#define REG_CTL_MD(BIT(4)|BIT(5)) /* CIR mode */
+
+/* Rx Config */
+#define SUNXI_IR_RXCTL_REG0x10
+#define REG_RXCTL_RPPIBIT(2) /* Pulse Polarity Invert flag */
+
+/* Rx Data */
+#define SUNXI_IR_RXFIFO_REG   0x20
+
+/* Rx Interrupt Enable */
+#define SUNXI_IR_RXINT_REG0x2C
+#define REG_RXINT_ROI_EN  BIT(0) /* Rx FIFO Overflow */
+#define REG_RXINT_RPEI_EN BIT(1) /* Rx Packet End */
+#define REG_RXINT_RAI_EN  BIT(4) /* Rx FIFO Data Available */
+/* Rx FIFO available byte level */
+#define REG_RXINT_RAL(val)(((val) << 8) & (BIT(8)|BIT(9)|BIT(10)|BIT(11)))
+
+/* Rx Interrupt Status */
+#define SUNXI_IR_RXSTA_REG0x30
+/* RX FIFO Get Available Counter */
+#define REG_RXSTA_GET_AC(val) (((val) >> 8) & (BIT(0)|BIT(1)|BIT(2)|BIT(3) \
+ |BIT(4)|BIT(5)))
+/* Clear all interrupt status value */
+#define REG_RXSTA_CLEARALL0xff
+
+/* IR Sample Config */
+#define SUNXI_IR_CIR_REG  0x34
+/* CIR_REG register noise threshold */
+#define REG_CIR_NTHR(val)(((val) << 2) & (BIT(2)|BIT(3)|BIT(4)|BIT(5) \
+|BIT(6)|BIT(7)))
+/* CIR_REG register idle threshold */
+#define REG_CIR_ITHR(val)(((val) << 8) & (BIT(8)|BIT(9)|BIT(10)|BIT(11) \
+|BIT(12)|BIT(13)|BIT(14)|BIT(15)))
+
+/* Hardware supported fifo size */
+#define SUNXI_IR_FIFO_SIZE16
+/* How many messages in FIFO trigger IRQ */
+#define TRIGGER_LEVEL 8
+/* Required frequency for IR0 or IR1 clock in CIR mode */
+#define SUNXI_IR_BASE_CLK 800
+/* Frequency after IR internal divider  */
+#define SUNXI_IR_CLK  (SUNXI_IR_BASE_CLK / 64)
+/* Sample period in ns */
+#define SUNXI_IR_SAMPLE   (10ul / SUNXI_IR_CLK)
+/* Noise threshold in samples  */
+#define SUNXI_IR_RXNOISE  1
+/* Idle Threshold in samples */
+#define SUNXI_IR_RXIDLE   20
+/* Time after which device stops sending data in ms */
+#define SUNXI_IR_TIMEOUT  120
+
+struct sunxi_ir {
+   spinlock_t  ir_lock;
+   struct rc_dev   *rc;
+   void __iomem*base;
+   int irq;
+   struct clk  *clk;
+   struct clk  *apb_clk;
+   const char  *map_name;
+};
+
+static irqreturn_t sunxi_ir_irq(int irqno, void *dev_i

[PATCH v8 3/3] ARM: sunxi: Add IR controller support in DT on A20

2014-05-25 Thread Alexander Bersenev
This patch adds IR controller in A20 Device-Tree:
- Two IR devices found in A20 user manual
- Pins for two devices
- One IR device physically found on Cubieboard 2
- One IR device physically found on Cubietruck

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts |  6 ++
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts  |  6 ++
 arch/arm/boot/dts/sun7i-a20.dtsi| 32 +
 3 files changed, 44 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts 
b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
index feeff64..b44d61b 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
@@ -65,6 +65,12 @@
};
};
 
+   ir0: ir@01c21800 {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins_a>;
+   status = "okay";
+   };
+
uart0: serial@01c28000 {
pinctrl-names = "default";
pinctrl-0 = <_pins_a>;
diff --git a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts 
b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
index e288562..5f5c31d 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
@@ -121,6 +121,12 @@
};
};
 
+   ir0: ir@01c21800 {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins_a>;
+   status = "okay";
+   };
+
uart0: serial@01c28000 {
pinctrl-names = "default";
pinctrl-0 = <_pins_a>;
diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index 0ae2b77..fe1f8ff 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -724,6 +724,20 @@
allwinner,drive = <2>;
allwinner,pull = <0>;
};
+
+   ir0_pins_a: ir0@0 {
+   allwinner,pins = "PB3","PB4";
+   allwinner,function = "ir0";
+   allwinner,drive = <0>;
+   allwinner,pull = <0>;
+   };
+
+   ir1_pins_a: ir1@0 {
+   allwinner,pins = "PB22","PB23";
+   allwinner,function = "ir1";
+   allwinner,drive = <0>;
+   allwinner,pull = <0>;
+   };
};
 
timer@01c20c00 {
@@ -749,6 +763,24 @@
interrupts = <0 24 4>;
};
 
+   ir0: ir@01c21800 {
+   compatible = "allwinner,sun7i-a20-ir";
+   clocks = <_gates 6>, <_clk>;
+   clock-names = "apb", "ir";
+   interrupts = <0 5 4>;
+   reg = <0x01c21800 0x40>;
+   status = "disabled";
+   };
+
+   ir1: ir@01c21c00 {
+   compatible = "allwinner,sun7i-a20-ir";
+   clocks = <_gates 7>, <_clk>;
+   clock-names = "apb", "ir";
+   interrupts = <0 6 4>;
+   reg = <0x01c21c00 0x40>;
+   status = "disabled";
+   };
+
lradc: lradc@01c22800 {
compatible = "allwinner,sun4i-lradc-keys";
reg = <0x01c22800 0x100>;
-- 
1.9.3

--
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/


[PATCH v8 0/3] ARM: sunxi: Add support for consumer infrared devices

2014-05-25 Thread Alexander Bersenev
This patch introduces Consumer IR(CIR) support for sunxi boards.

This is based on Alexsey Shestacov's work based on the original driver 
supplied by Allwinner.

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 

---
Changes since version 1: 
 - Fix timer memory leaks 
 - Fix race condition when driver unloads while interrupt handler is active
 - Support Cubieboard 2(need testing)

Changes since version 2:
- More reliable keydown events
- Documentation fixes
- Rename registers accurding to A20 user manual
- Remove some includes, order includes alphabetically
- Use BIT macro
- Typo fixes

Changes since version 3:
- Split the patch on smaller parts
- More documentation fixes
- Add clock-names in DT
- Use devm_clk_get function to get the clocks
- Removed gpios property from ir's DT
- Changed compatible from allwinner,sunxi-ir to allwinner,sun7i-a20-ir in DT
- Use spin_lock_irq instead spin_lock_irqsave in interrupt handler
- Add myself in the copyright ;)
- Coding style and indentation fixes

Changes since version 4:
- Try to fix indentation errors by sending patches with git send-mail

Changes since version 5:
- More indentation fixes
- Make patches pass checkpatch with --strict option
- Replaced magic numbers with defines(patch by Priit Laes)
- Fixed oops on loading(patch by Hans de Goede)

Changes since version 6:
- Removed constants from code
- Better errrors handling on loading
- Renamed sunxi-ir.c to sunxi-cir.c
- Changed description of second commit
- Order entries in dts and dtsi by register address
- Code style fixes

Changes since version 7:
- Removed a couple of blank lines in code
- Delay interrupts init until we are ready to handle them
- Increased the reported duration of each pulse by one
- Refactored defines

Alexander Bersenev (3):
  ARM: sunxi: Add documentation for sunxi consumer infrared devices
  [media] rc: add sunxi-ir driver
  ARM: sunxi: Add IR controller support in DT on A20

 .../devicetree/bindings/media/sunxi-ir.txt |  23 ++
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts|   6 +
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts |   6 +
 arch/arm/boot/dts/sun7i-a20.dtsi   |  32 +++
 drivers/media/rc/Kconfig   |  10 +
 drivers/media/rc/Makefile  |   1 +
 drivers/media/rc/sunxi-cir.c   | 313 +
 7 files changed, 391 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt
 create mode 100644 drivers/media/rc/sunxi-cir.c

-- 
1.9.3

--
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/


[PATCH v8 0/3] ARM: sunxi: Add support for consumer infrared devices

2014-05-25 Thread Alexander Bersenev
This patch introduces Consumer IR(CIR) support for sunxi boards.

This is based on Alexsey Shestacov's work based on the original driver 
supplied by Allwinner.

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org

---
Changes since version 1: 
 - Fix timer memory leaks 
 - Fix race condition when driver unloads while interrupt handler is active
 - Support Cubieboard 2(need testing)

Changes since version 2:
- More reliable keydown events
- Documentation fixes
- Rename registers accurding to A20 user manual
- Remove some includes, order includes alphabetically
- Use BIT macro
- Typo fixes

Changes since version 3:
- Split the patch on smaller parts
- More documentation fixes
- Add clock-names in DT
- Use devm_clk_get function to get the clocks
- Removed gpios property from ir's DT
- Changed compatible from allwinner,sunxi-ir to allwinner,sun7i-a20-ir in DT
- Use spin_lock_irq instead spin_lock_irqsave in interrupt handler
- Add myself in the copyright ;)
- Coding style and indentation fixes

Changes since version 4:
- Try to fix indentation errors by sending patches with git send-mail

Changes since version 5:
- More indentation fixes
- Make patches pass checkpatch with --strict option
- Replaced magic numbers with defines(patch by Priit Laes)
- Fixed oops on loading(patch by Hans de Goede)

Changes since version 6:
- Removed constants from code
- Better errrors handling on loading
- Renamed sunxi-ir.c to sunxi-cir.c
- Changed description of second commit
- Order entries in dts and dtsi by register address
- Code style fixes

Changes since version 7:
- Removed a couple of blank lines in code
- Delay interrupts init until we are ready to handle them
- Increased the reported duration of each pulse by one
- Refactored defines

Alexander Bersenev (3):
  ARM: sunxi: Add documentation for sunxi consumer infrared devices
  [media] rc: add sunxi-ir driver
  ARM: sunxi: Add IR controller support in DT on A20

 .../devicetree/bindings/media/sunxi-ir.txt |  23 ++
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts|   6 +
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts |   6 +
 arch/arm/boot/dts/sun7i-a20.dtsi   |  32 +++
 drivers/media/rc/Kconfig   |  10 +
 drivers/media/rc/Makefile  |   1 +
 drivers/media/rc/sunxi-cir.c   | 313 +
 7 files changed, 391 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt
 create mode 100644 drivers/media/rc/sunxi-cir.c

-- 
1.9.3

--
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/


[PATCH v8 3/3] ARM: sunxi: Add IR controller support in DT on A20

2014-05-25 Thread Alexander Bersenev
This patch adds IR controller in A20 Device-Tree:
- Two IR devices found in A20 user manual
- Pins for two devices
- One IR device physically found on Cubieboard 2
- One IR device physically found on Cubietruck

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts |  6 ++
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts  |  6 ++
 arch/arm/boot/dts/sun7i-a20.dtsi| 32 +
 3 files changed, 44 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts 
b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
index feeff64..b44d61b 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
@@ -65,6 +65,12 @@
};
};
 
+   ir0: ir@01c21800 {
+   pinctrl-names = default;
+   pinctrl-0 = ir0_pins_a;
+   status = okay;
+   };
+
uart0: serial@01c28000 {
pinctrl-names = default;
pinctrl-0 = uart0_pins_a;
diff --git a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts 
b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
index e288562..5f5c31d 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
@@ -121,6 +121,12 @@
};
};
 
+   ir0: ir@01c21800 {
+   pinctrl-names = default;
+   pinctrl-0 = ir0_pins_a;
+   status = okay;
+   };
+
uart0: serial@01c28000 {
pinctrl-names = default;
pinctrl-0 = uart0_pins_a;
diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index 0ae2b77..fe1f8ff 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -724,6 +724,20 @@
allwinner,drive = 2;
allwinner,pull = 0;
};
+
+   ir0_pins_a: ir0@0 {
+   allwinner,pins = PB3,PB4;
+   allwinner,function = ir0;
+   allwinner,drive = 0;
+   allwinner,pull = 0;
+   };
+
+   ir1_pins_a: ir1@0 {
+   allwinner,pins = PB22,PB23;
+   allwinner,function = ir1;
+   allwinner,drive = 0;
+   allwinner,pull = 0;
+   };
};
 
timer@01c20c00 {
@@ -749,6 +763,24 @@
interrupts = 0 24 4;
};
 
+   ir0: ir@01c21800 {
+   compatible = allwinner,sun7i-a20-ir;
+   clocks = apb0_gates 6, ir0_clk;
+   clock-names = apb, ir;
+   interrupts = 0 5 4;
+   reg = 0x01c21800 0x40;
+   status = disabled;
+   };
+
+   ir1: ir@01c21c00 {
+   compatible = allwinner,sun7i-a20-ir;
+   clocks = apb0_gates 7, ir1_clk;
+   clock-names = apb, ir;
+   interrupts = 0 6 4;
+   reg = 0x01c21c00 0x40;
+   status = disabled;
+   };
+
lradc: lradc@01c22800 {
compatible = allwinner,sun4i-lradc-keys;
reg = 0x01c22800 0x100;
-- 
1.9.3

--
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/


[PATCH v8 2/3] [media] rc: add sunxi-ir driver

2014-05-25 Thread Alexander Bersenev
This patch adds driver for sunxi IR controller.
It is based on Alexsey Shestacov's work based on the original driver
supplied by Allwinner.

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 drivers/media/rc/Kconfig |  10 ++
 drivers/media/rc/Makefile|   1 +
 drivers/media/rc/sunxi-cir.c | 313 +++
 3 files changed, 324 insertions(+)
 create mode 100644 drivers/media/rc/sunxi-cir.c

diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 8fbd377..9427fad 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -343,4 +343,14 @@ config RC_ST
 
 If you're not sure, select N here.
 
+config IR_SUNXI
+tristate SUNXI IR remote control
+depends on RC_CORE
+depends on ARCH_SUNXI
+---help---
+  Say Y if you want to use sunXi internal IR Controller
+
+  To compile this driver as a module, choose M here: the module will
+  be called sunxi-ir.
+
 endif #RC_DEVICES
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index f8b54ff..9ee9ee7 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -32,4 +32,5 @@ 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_SUNXI) += sunxi-cir.o
 obj-$(CONFIG_IR_IMG) += img-ir/
diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c
new file mode 100644
index 000..245d8dc
--- /dev/null
+++ b/drivers/media/rc/sunxi-cir.c
@@ -0,0 +1,313 @@
+/*
+ * Driver for Allwinner sunXi IR controller
+ *
+ * Copyright (C) 2014 Alexsey Shestacov wingr...@linux-sunxi.org
+ * Copyright (C) 2014 Alexander Bersenev b...@hackerdom.ru
+ *
+ * Based on sun5i-ir.c:
+ * Copyright (C) 2007-2012 Daniel Wang
+ * Allwinner Technology Co., Ltd. www.allwinnertech.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/clk.h
+#include linux/interrupt.h
+#include linux/module.h
+#include linux/of_platform.h
+#include media/rc-core.h
+
+#define SUNXI_IR_DEV sunxi-ir
+
+/* Registers */
+/* IR Control */
+#define SUNXI_IR_CTL_REG  0x00
+#define REG_CTL_GEN   BIT(0) /* Global Enable */
+#define REG_CTL_RXEN  BIT(1) /* RX block enable */
+#define REG_CTL_MD(BIT(4)|BIT(5)) /* CIR mode */
+
+/* Rx Config */
+#define SUNXI_IR_RXCTL_REG0x10
+#define REG_RXCTL_RPPIBIT(2) /* Pulse Polarity Invert flag */
+
+/* Rx Data */
+#define SUNXI_IR_RXFIFO_REG   0x20
+
+/* Rx Interrupt Enable */
+#define SUNXI_IR_RXINT_REG0x2C
+#define REG_RXINT_ROI_EN  BIT(0) /* Rx FIFO Overflow */
+#define REG_RXINT_RPEI_EN BIT(1) /* Rx Packet End */
+#define REG_RXINT_RAI_EN  BIT(4) /* Rx FIFO Data Available */
+/* Rx FIFO available byte level */
+#define REG_RXINT_RAL(val)(((val)  8)  (BIT(8)|BIT(9)|BIT(10)|BIT(11)))
+
+/* Rx Interrupt Status */
+#define SUNXI_IR_RXSTA_REG0x30
+/* RX FIFO Get Available Counter */
+#define REG_RXSTA_GET_AC(val) (((val)  8)  (BIT(0)|BIT(1)|BIT(2)|BIT(3) \
+ |BIT(4)|BIT(5)))
+/* Clear all interrupt status value */
+#define REG_RXSTA_CLEARALL0xff
+
+/* IR Sample Config */
+#define SUNXI_IR_CIR_REG  0x34
+/* CIR_REG register noise threshold */
+#define REG_CIR_NTHR(val)(((val)  2)  (BIT(2)|BIT(3)|BIT(4)|BIT(5) \
+|BIT(6)|BIT(7)))
+/* CIR_REG register idle threshold */
+#define REG_CIR_ITHR(val)(((val)  8)  (BIT(8)|BIT(9)|BIT(10)|BIT(11) \
+|BIT(12)|BIT(13)|BIT(14)|BIT(15)))
+
+/* Hardware supported fifo size */
+#define SUNXI_IR_FIFO_SIZE16
+/* How many messages in FIFO trigger IRQ */
+#define TRIGGER_LEVEL 8
+/* Required frequency for IR0 or IR1 clock in CIR mode */
+#define SUNXI_IR_BASE_CLK 800
+/* Frequency after IR internal divider  */
+#define SUNXI_IR_CLK  (SUNXI_IR_BASE_CLK / 64)
+/* Sample period in ns */
+#define SUNXI_IR_SAMPLE   (10ul / SUNXI_IR_CLK)
+/* Noise threshold in samples  */
+#define SUNXI_IR_RXNOISE  1
+/* Idle Threshold in samples */
+#define SUNXI_IR_RXIDLE   20
+/* Time after which device stops sending data in ms */
+#define SUNXI_IR_TIMEOUT  120
+
+struct sunxi_ir {
+   spinlock_t  ir_lock;
+   struct rc_dev   *rc;
+   void __iomem*base;
+   int irq;
+   struct clk  *clk;
+   struct clk  *apb_clk

[PATCH v8 1/3] ARM: sunxi: Add documentation for sunxi consumer infrared devices

2014-05-25 Thread Alexander Bersenev
This patch adds documentation for Device-Tree bindings for sunxi IR
controller.

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 .../devicetree/bindings/media/sunxi-ir.txt | 23 ++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt

diff --git a/Documentation/devicetree/bindings/media/sunxi-ir.txt 
b/Documentation/devicetree/bindings/media/sunxi-ir.txt
new file mode 100644
index 000..014dd8b
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/sunxi-ir.txt
@@ -0,0 +1,23 @@
+Device-Tree bindings for SUNXI IR controller found in sunXi SoC family
+
+Required properties:
+- compatible   : should be allwinner,sun7i-a20-ir;
+- clocks   : list of clock specifiers, corresponding to
+ entries in clock-names property;
+- clock-names  : should contain apb and ir entries;
+- interrupts   : should contain IR IRQ number;
+- reg  : should contain IO map address for IR.
+
+Optional properties:
+- linux,rc-map-name : Remote control map name.
+
+Example:
+
+ir0: ir@01c21800 {
+   compatible = allwinner,sun7i-a20-ir;
+   clocks = apb0_gates 6, ir0_clk;
+   clock-names = apb, ir;
+   interrupts = 0 5 1;
+   reg = 0x01C21800 0x40;
+   linux,rc-map-name = rc-rc6-mce;
+};
-- 
1.9.3

--
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/


[PATCH v7 3/3] ARM: sunxi: Add IR controller support in DT on A20

2014-05-14 Thread Alexander Bersenev
This patch adds IR controller in A20 Device-Tree:
- Two IR devices found in A20 user manual
- Pins for two devices
- One IR device physically found on Cubieboard 2
- One IR device physically found on Cubietruck

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts |  6 ++
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts  |  6 ++
 arch/arm/boot/dts/sun7i-a20.dtsi| 32 +
 3 files changed, 44 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts 
b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
index feeff64..b44d61b 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
@@ -65,6 +65,12 @@
};
};
 
+   ir0: ir@01c21800 {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins_a>;
+   status = "okay";
+   };
+
uart0: serial@01c28000 {
pinctrl-names = "default";
pinctrl-0 = <_pins_a>;
diff --git a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts 
b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
index e288562..5f5c31d 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
@@ -121,6 +121,12 @@
};
};
 
+   ir0: ir@01c21800 {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins_a>;
+   status = "okay";
+   };
+
uart0: serial@01c28000 {
pinctrl-names = "default";
pinctrl-0 = <_pins_a>;
diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index 0ae2b77..fe1f8ff 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -724,6 +724,20 @@
allwinner,drive = <2>;
allwinner,pull = <0>;
};
+
+   ir0_pins_a: ir0@0 {
+   allwinner,pins = "PB3","PB4";
+   allwinner,function = "ir0";
+   allwinner,drive = <0>;
+   allwinner,pull = <0>;
+   };
+
+   ir1_pins_a: ir1@0 {
+   allwinner,pins = "PB22","PB23";
+   allwinner,function = "ir1";
+   allwinner,drive = <0>;
+   allwinner,pull = <0>;
+   };
};
 
timer@01c20c00 {
@@ -749,6 +763,24 @@
interrupts = <0 24 4>;
};
 
+   ir0: ir@01c21800 {
+   compatible = "allwinner,sun7i-a20-ir";
+   clocks = <_gates 6>, <_clk>;
+   clock-names = "apb", "ir";
+   interrupts = <0 5 4>;
+   reg = <0x01c21800 0x40>;
+   status = "disabled";
+   };
+
+   ir1: ir@01c21c00 {
+   compatible = "allwinner,sun7i-a20-ir";
+   clocks = <_gates 7>, <_clk>;
+   clock-names = "apb", "ir";
+   interrupts = <0 6 4>;
+   reg = <0x01c21c00 0x40>;
+   status = "disabled";
+   };
+
lradc: lradc@01c22800 {
compatible = "allwinner,sun4i-lradc-keys";
reg = <0x01c22800 0x100>;
-- 
1.9.3

--
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/


[PATCH v7 1/3] ARM: sunxi: Add documentation for sunxi consumer infrared devices

2014-05-14 Thread Alexander Bersenev
This patch adds documentation for Device-Tree bindings for sunxi IR
controller.

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 .../devicetree/bindings/media/sunxi-ir.txt | 23 ++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt

diff --git a/Documentation/devicetree/bindings/media/sunxi-ir.txt 
b/Documentation/devicetree/bindings/media/sunxi-ir.txt
new file mode 100644
index 000..014dd8b
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/sunxi-ir.txt
@@ -0,0 +1,23 @@
+Device-Tree bindings for SUNXI IR controller found in sunXi SoC family
+
+Required properties:
+- compatible   : should be "allwinner,sun7i-a20-ir";
+- clocks   : list of clock specifiers, corresponding to
+ entries in clock-names property;
+- clock-names  : should contain "apb" and "ir" entries;
+- interrupts   : should contain IR IRQ number;
+- reg  : should contain IO map address for IR.
+
+Optional properties:
+- linux,rc-map-name : Remote control map name.
+
+Example:
+
+ir0: ir@01c21800 {
+   compatible = "allwinner,sun7i-a20-ir";
+   clocks = <_gates 6>, <_clk>;
+   clock-names = "apb", "ir";
+   interrupts = <0 5 1>;
+   reg = <0x01C21800 0x40>;
+   linux,rc-map-name = "rc-rc6-mce";
+};
-- 
1.9.3

--
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/


[PATCH v7 2/3] [media] rc: add sunxi-ir driver

2014-05-14 Thread Alexander Bersenev
This patch adds driver for sunxi IR controller.
It is based on Alexsey Shestacov's work based on the original driver
supplied by Allwinner.

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 drivers/media/rc/Kconfig |  10 ++
 drivers/media/rc/Makefile|   1 +
 drivers/media/rc/sunxi-cir.c | 334 +++
 3 files changed, 345 insertions(+)
 create mode 100644 drivers/media/rc/sunxi-cir.c

diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 8fbd377..9427fad 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -343,4 +343,14 @@ config RC_ST
 
 If you're not sure, select N here.
 
+config IR_SUNXI
+tristate "SUNXI IR remote control"
+depends on RC_CORE
+depends on ARCH_SUNXI
+---help---
+  Say Y if you want to use sunXi internal IR Controller
+
+  To compile this driver as a module, choose M here: the module will
+  be called sunxi-ir.
+
 endif #RC_DEVICES
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index f8b54ff..9ee9ee7 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -32,4 +32,5 @@ 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_SUNXI) += sunxi-cir.o
 obj-$(CONFIG_IR_IMG) += img-ir/
diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c
new file mode 100644
index 000..25eb175
--- /dev/null
+++ b/drivers/media/rc/sunxi-cir.c
@@ -0,0 +1,334 @@
+/*
+ * Driver for Allwinner sunXi IR controller
+ *
+ * Copyright (C) 2014 Alexsey Shestacov 
+ * Copyright (C) 2014 Alexander Bersenev 
+ *
+ * Based on sun5i-ir.c:
+ * Copyright (C) 2007-2012 Daniel Wang
+ * Allwinner Technology Co., 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define SUNXI_IR_DEV "sunxi-ir"
+
+/* Registers */
+/* IR Control */
+#define SUNXI_IR_CTL_REG  0x00
+/* Rx Config */
+#define SUNXI_IR_RXCTL_REG0x10
+/* Rx Data */
+#define SUNXI_IR_RXFIFO_REG   0x20
+/* Rx Interrupt Enable */
+#define SUNXI_IR_RXINT_REG0x2C
+/* Rx Interrupt Status */
+#define SUNXI_IR_RXSTA_REG0x30
+/* IR Sample Config */
+#define SUNXI_IR_CIR_REG  0x34
+
+/* Global Enable for IR_CTL Register */
+#define REG_CTL_GEN   BIT(0)
+/* RX block enable for IR_CTL Register */
+#define REG_CTL_RXEN  BIT(1)
+/* CIR mode for IR_CTL Register */
+#define REG_CTL_MD(BIT(4)|BIT(5))
+
+/* IR_RXCTL_REG Register Receiver Pulse Polarity Invert flag */
+#define REG_RXCTL_RPPIBIT(2)
+
+/* IR_RXINT_REG Register fields */
+#define REG_RXINT_ROI_EN  BIT(0) /* Rx FIFO Overflow */
+#define REG_RXINT_RPEI_EN BIT(1) /* Rx Packet End */
+#define REG_RXINT_RAI_EN  BIT(4) /* Rx FIFO Data Available */
+/* Rx FIFO available byte level */
+#define REG_RXINT_RAL__MASK   (BIT(8)|BIT(9)|BIT(10)|BIT(11))
+#define REG_RXINT_RAL__SHIFT  8
+static inline uint32_t REG_RXINT_RAL(uint16_t val)
+{
+   return (val << REG_RXINT_RAL__SHIFT) & REG_RXINT_RAL__MASK;
+}
+
+/* CIR_REG register noise threshold */
+#define REG_CIR_NTHR__MASK   (BIT(2)|BIT(3)|BIT(4)|BIT(5)|BIT(6)|BIT(7))
+#define REG_CIR_NTHR__SHIFT  2
+static inline uint32_t REG_CIR_NTHR(uint16_t val)
+{
+   return (val << REG_CIR_NTHR__SHIFT) & REG_CIR_NTHR__MASK;
+}
+/* CIR_REG register idle threshold */
+#define REG_CIR_ITHR__MASK   (BIT(8)|BIT(9)|BIT(10)|BIT(11)|BIT(12)|BIT(13) \
+|BIT(14)|BIT(15))
+#define REG_CIR_ITHR__SHIFT  8
+static inline uint32_t REG_CIR_ITHR(uint16_t val)
+{
+   return (val << REG_CIR_ITHR__SHIFT) & REG_CIR_ITHR__MASK;
+}
+
+/* RXSTA_REG Register RX FIFO Available Counter */
+#define REG_RXSTA_RAC__SHIFT  8
+#define REG_RXSTA_RAC__MASK   0x3f
+
+/* Clear all interrupt status value */
+#define REG_RXSTA_CLEARALL0xff
+
+/* Hardware supported fifo size */
+#define SUNXI_IR_FIFO_SIZE16
+/* How many messages in FIFO trigger IRQ */
+#define TRIGGER_LEVEL 8
+/* Required frequency for IR0 or IR1 clock in CIR mode */
+#define SUNXI_IR_BASE_CLK 800
+/* Frequency after IR internal divider  */
+#define SUNXI_IR_CLK  (SUNXI_IR_BASE_CLK / 64)
+/* Sample period in ns */
+#define SUNXI_IR_SAMPLE   (10ul / SUNXI_IR_CLK)
+/* Noise threshold in samples  */
+#define SUNXI_IR_RXNOISE  1
+/* Idl

[PATCH v7 0/3] ARM: sunxi: Add support for consumer infrared devices

2014-05-14 Thread Alexander Bersenev
This patch introduces Consumer IR(CIR) support for sunxi boards.

This is based on Alexsey Shestacov's work based on the original driver 
supplied by Allwinner.

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 

---
Changes since version 1: 
 - Fix timer memory leaks 
 - Fix race condition when driver unloads while interrupt handler is active
 - Support Cubieboard 2(need testing)

Changes since version 2:
- More reliable keydown events
- Documentation fixes
- Rename registers accurding to A20 user manual
- Remove some includes, order includes alphabetically
- Use BIT macro
- Typo fixes

Changes since version 3:
- Split the patch on smaller parts
- More documentation fixes
- Add clock-names in DT
- Use devm_clk_get function to get the clocks
- Removed gpios property from ir's DT
- Changed compatible from allwinner,sunxi-ir to allwinner,sun7i-a20-ir in DT
- Use spin_lock_irq instead spin_lock_irqsave in interrupt handler
- Add myself in the copyright ;)
- Coding style and indentation fixes

Changes since version 4:
- Try to fix indentation errors by sending patches with git send-mail

Changes since version 5:
- More indentation fixes
- Make patches pass checkpatch with --strict option
- Replaced magic numbers with defines(patch by Priit Laes)
- Fixed oops on loading(patch by Hans de Goede)

Changes since version 6:
- Removed constants from code
- Better errrors handling on loading
- Renamed sunxi-ir.c to sunxi-cir.c
- Changed description of second commit
- Order entries in dts and dtsi by register address
- Code style fixes


Alexander Bersenev (3):
  ARM: sunxi: Add documentation for sunxi consumer infrared devices
  [media] rc: add sunxi-ir driver
  ARM: sunxi: Add IR controller support in DT on A20

 .../devicetree/bindings/media/sunxi-ir.txt |  23 ++
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts|   6 +
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts |   6 +
 arch/arm/boot/dts/sun7i-a20.dtsi   |  32 ++
 drivers/media/rc/Kconfig   |  10 +
 drivers/media/rc/Makefile  |   1 +
 drivers/media/rc/sunxi-cir.c   | 334 +
 7 files changed, 412 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt
 create mode 100644 drivers/media/rc/sunxi-cir.c

-- 
1.9.3
--
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/


[PATCH v7 0/3] ARM: sunxi: Add support for consumer infrared devices

2014-05-14 Thread Alexander Bersenev
This patch introduces Consumer IR(CIR) support for sunxi boards.

This is based on Alexsey Shestacov's work based on the original driver 
supplied by Allwinner.

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org

---
Changes since version 1: 
 - Fix timer memory leaks 
 - Fix race condition when driver unloads while interrupt handler is active
 - Support Cubieboard 2(need testing)

Changes since version 2:
- More reliable keydown events
- Documentation fixes
- Rename registers accurding to A20 user manual
- Remove some includes, order includes alphabetically
- Use BIT macro
- Typo fixes

Changes since version 3:
- Split the patch on smaller parts
- More documentation fixes
- Add clock-names in DT
- Use devm_clk_get function to get the clocks
- Removed gpios property from ir's DT
- Changed compatible from allwinner,sunxi-ir to allwinner,sun7i-a20-ir in DT
- Use spin_lock_irq instead spin_lock_irqsave in interrupt handler
- Add myself in the copyright ;)
- Coding style and indentation fixes

Changes since version 4:
- Try to fix indentation errors by sending patches with git send-mail

Changes since version 5:
- More indentation fixes
- Make patches pass checkpatch with --strict option
- Replaced magic numbers with defines(patch by Priit Laes)
- Fixed oops on loading(patch by Hans de Goede)

Changes since version 6:
- Removed constants from code
- Better errrors handling on loading
- Renamed sunxi-ir.c to sunxi-cir.c
- Changed description of second commit
- Order entries in dts and dtsi by register address
- Code style fixes


Alexander Bersenev (3):
  ARM: sunxi: Add documentation for sunxi consumer infrared devices
  [media] rc: add sunxi-ir driver
  ARM: sunxi: Add IR controller support in DT on A20

 .../devicetree/bindings/media/sunxi-ir.txt |  23 ++
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts|   6 +
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts |   6 +
 arch/arm/boot/dts/sun7i-a20.dtsi   |  32 ++
 drivers/media/rc/Kconfig   |  10 +
 drivers/media/rc/Makefile  |   1 +
 drivers/media/rc/sunxi-cir.c   | 334 +
 7 files changed, 412 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt
 create mode 100644 drivers/media/rc/sunxi-cir.c

-- 
1.9.3
--
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/


[PATCH v7 2/3] [media] rc: add sunxi-ir driver

2014-05-14 Thread Alexander Bersenev
This patch adds driver for sunxi IR controller.
It is based on Alexsey Shestacov's work based on the original driver
supplied by Allwinner.

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 drivers/media/rc/Kconfig |  10 ++
 drivers/media/rc/Makefile|   1 +
 drivers/media/rc/sunxi-cir.c | 334 +++
 3 files changed, 345 insertions(+)
 create mode 100644 drivers/media/rc/sunxi-cir.c

diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 8fbd377..9427fad 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -343,4 +343,14 @@ config RC_ST
 
 If you're not sure, select N here.
 
+config IR_SUNXI
+tristate SUNXI IR remote control
+depends on RC_CORE
+depends on ARCH_SUNXI
+---help---
+  Say Y if you want to use sunXi internal IR Controller
+
+  To compile this driver as a module, choose M here: the module will
+  be called sunxi-ir.
+
 endif #RC_DEVICES
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index f8b54ff..9ee9ee7 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -32,4 +32,5 @@ 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_SUNXI) += sunxi-cir.o
 obj-$(CONFIG_IR_IMG) += img-ir/
diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c
new file mode 100644
index 000..25eb175
--- /dev/null
+++ b/drivers/media/rc/sunxi-cir.c
@@ -0,0 +1,334 @@
+/*
+ * Driver for Allwinner sunXi IR controller
+ *
+ * Copyright (C) 2014 Alexsey Shestacov wingr...@linux-sunxi.org
+ * Copyright (C) 2014 Alexander Bersenev b...@hackerdom.ru
+ *
+ * Based on sun5i-ir.c:
+ * Copyright (C) 2007-2012 Daniel Wang
+ * Allwinner Technology Co., Ltd. www.allwinnertech.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/clk.h
+#include linux/interrupt.h
+#include linux/module.h
+#include linux/of_platform.h
+#include media/rc-core.h
+
+#define SUNXI_IR_DEV sunxi-ir
+
+/* Registers */
+/* IR Control */
+#define SUNXI_IR_CTL_REG  0x00
+/* Rx Config */
+#define SUNXI_IR_RXCTL_REG0x10
+/* Rx Data */
+#define SUNXI_IR_RXFIFO_REG   0x20
+/* Rx Interrupt Enable */
+#define SUNXI_IR_RXINT_REG0x2C
+/* Rx Interrupt Status */
+#define SUNXI_IR_RXSTA_REG0x30
+/* IR Sample Config */
+#define SUNXI_IR_CIR_REG  0x34
+
+/* Global Enable for IR_CTL Register */
+#define REG_CTL_GEN   BIT(0)
+/* RX block enable for IR_CTL Register */
+#define REG_CTL_RXEN  BIT(1)
+/* CIR mode for IR_CTL Register */
+#define REG_CTL_MD(BIT(4)|BIT(5))
+
+/* IR_RXCTL_REG Register Receiver Pulse Polarity Invert flag */
+#define REG_RXCTL_RPPIBIT(2)
+
+/* IR_RXINT_REG Register fields */
+#define REG_RXINT_ROI_EN  BIT(0) /* Rx FIFO Overflow */
+#define REG_RXINT_RPEI_EN BIT(1) /* Rx Packet End */
+#define REG_RXINT_RAI_EN  BIT(4) /* Rx FIFO Data Available */
+/* Rx FIFO available byte level */
+#define REG_RXINT_RAL__MASK   (BIT(8)|BIT(9)|BIT(10)|BIT(11))
+#define REG_RXINT_RAL__SHIFT  8
+static inline uint32_t REG_RXINT_RAL(uint16_t val)
+{
+   return (val  REG_RXINT_RAL__SHIFT)  REG_RXINT_RAL__MASK;
+}
+
+/* CIR_REG register noise threshold */
+#define REG_CIR_NTHR__MASK   (BIT(2)|BIT(3)|BIT(4)|BIT(5)|BIT(6)|BIT(7))
+#define REG_CIR_NTHR__SHIFT  2
+static inline uint32_t REG_CIR_NTHR(uint16_t val)
+{
+   return (val  REG_CIR_NTHR__SHIFT)  REG_CIR_NTHR__MASK;
+}
+/* CIR_REG register idle threshold */
+#define REG_CIR_ITHR__MASK   (BIT(8)|BIT(9)|BIT(10)|BIT(11)|BIT(12)|BIT(13) \
+|BIT(14)|BIT(15))
+#define REG_CIR_ITHR__SHIFT  8
+static inline uint32_t REG_CIR_ITHR(uint16_t val)
+{
+   return (val  REG_CIR_ITHR__SHIFT)  REG_CIR_ITHR__MASK;
+}
+
+/* RXSTA_REG Register RX FIFO Available Counter */
+#define REG_RXSTA_RAC__SHIFT  8
+#define REG_RXSTA_RAC__MASK   0x3f
+
+/* Clear all interrupt status value */
+#define REG_RXSTA_CLEARALL0xff
+
+/* Hardware supported fifo size */
+#define SUNXI_IR_FIFO_SIZE16
+/* How many messages in FIFO trigger IRQ */
+#define TRIGGER_LEVEL 8
+/* Required frequency for IR0 or IR1 clock in CIR mode */
+#define SUNXI_IR_BASE_CLK 800
+/* Frequency after IR internal divider  */
+#define SUNXI_IR_CLK  (SUNXI_IR_BASE_CLK / 64)
+/* Sample period in ns */
+#define

[PATCH v7 3/3] ARM: sunxi: Add IR controller support in DT on A20

2014-05-14 Thread Alexander Bersenev
This patch adds IR controller in A20 Device-Tree:
- Two IR devices found in A20 user manual
- Pins for two devices
- One IR device physically found on Cubieboard 2
- One IR device physically found on Cubietruck

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts |  6 ++
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts  |  6 ++
 arch/arm/boot/dts/sun7i-a20.dtsi| 32 +
 3 files changed, 44 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts 
b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
index feeff64..b44d61b 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
@@ -65,6 +65,12 @@
};
};
 
+   ir0: ir@01c21800 {
+   pinctrl-names = default;
+   pinctrl-0 = ir0_pins_a;
+   status = okay;
+   };
+
uart0: serial@01c28000 {
pinctrl-names = default;
pinctrl-0 = uart0_pins_a;
diff --git a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts 
b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
index e288562..5f5c31d 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
@@ -121,6 +121,12 @@
};
};
 
+   ir0: ir@01c21800 {
+   pinctrl-names = default;
+   pinctrl-0 = ir0_pins_a;
+   status = okay;
+   };
+
uart0: serial@01c28000 {
pinctrl-names = default;
pinctrl-0 = uart0_pins_a;
diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index 0ae2b77..fe1f8ff 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -724,6 +724,20 @@
allwinner,drive = 2;
allwinner,pull = 0;
};
+
+   ir0_pins_a: ir0@0 {
+   allwinner,pins = PB3,PB4;
+   allwinner,function = ir0;
+   allwinner,drive = 0;
+   allwinner,pull = 0;
+   };
+
+   ir1_pins_a: ir1@0 {
+   allwinner,pins = PB22,PB23;
+   allwinner,function = ir1;
+   allwinner,drive = 0;
+   allwinner,pull = 0;
+   };
};
 
timer@01c20c00 {
@@ -749,6 +763,24 @@
interrupts = 0 24 4;
};
 
+   ir0: ir@01c21800 {
+   compatible = allwinner,sun7i-a20-ir;
+   clocks = apb0_gates 6, ir0_clk;
+   clock-names = apb, ir;
+   interrupts = 0 5 4;
+   reg = 0x01c21800 0x40;
+   status = disabled;
+   };
+
+   ir1: ir@01c21c00 {
+   compatible = allwinner,sun7i-a20-ir;
+   clocks = apb0_gates 7, ir1_clk;
+   clock-names = apb, ir;
+   interrupts = 0 6 4;
+   reg = 0x01c21c00 0x40;
+   status = disabled;
+   };
+
lradc: lradc@01c22800 {
compatible = allwinner,sun4i-lradc-keys;
reg = 0x01c22800 0x100;
-- 
1.9.3

--
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/


[PATCH v7 1/3] ARM: sunxi: Add documentation for sunxi consumer infrared devices

2014-05-14 Thread Alexander Bersenev
This patch adds documentation for Device-Tree bindings for sunxi IR
controller.

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 .../devicetree/bindings/media/sunxi-ir.txt | 23 ++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt

diff --git a/Documentation/devicetree/bindings/media/sunxi-ir.txt 
b/Documentation/devicetree/bindings/media/sunxi-ir.txt
new file mode 100644
index 000..014dd8b
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/sunxi-ir.txt
@@ -0,0 +1,23 @@
+Device-Tree bindings for SUNXI IR controller found in sunXi SoC family
+
+Required properties:
+- compatible   : should be allwinner,sun7i-a20-ir;
+- clocks   : list of clock specifiers, corresponding to
+ entries in clock-names property;
+- clock-names  : should contain apb and ir entries;
+- interrupts   : should contain IR IRQ number;
+- reg  : should contain IO map address for IR.
+
+Optional properties:
+- linux,rc-map-name : Remote control map name.
+
+Example:
+
+ir0: ir@01c21800 {
+   compatible = allwinner,sun7i-a20-ir;
+   clocks = apb0_gates 6, ir0_clk;
+   clock-names = apb, ir;
+   interrupts = 0 5 1;
+   reg = 0x01C21800 0x40;
+   linux,rc-map-name = rc-rc6-mce;
+};
-- 
1.9.3

--
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/


[PATCH v6 1/3] ARM: sunxi: Add documentation for sunxi consumer infrared devices

2014-05-13 Thread Alexander Bersenev
This patch adds documentation for Device-Tree bindings for sunxi IR
controller.

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 .../devicetree/bindings/media/sunxi-ir.txt | 23 ++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt

diff --git a/Documentation/devicetree/bindings/media/sunxi-ir.txt 
b/Documentation/devicetree/bindings/media/sunxi-ir.txt
new file mode 100644
index 000..014dd8b
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/sunxi-ir.txt
@@ -0,0 +1,23 @@
+Device-Tree bindings for SUNXI IR controller found in sunXi SoC family
+
+Required properties:
+- compatible   : should be "allwinner,sun7i-a20-ir";
+- clocks   : list of clock specifiers, corresponding to
+ entries in clock-names property;
+- clock-names  : should contain "apb" and "ir" entries;
+- interrupts   : should contain IR IRQ number;
+- reg  : should contain IO map address for IR.
+
+Optional properties:
+- linux,rc-map-name : Remote control map name.
+
+Example:
+
+ir0: ir@01c21800 {
+   compatible = "allwinner,sun7i-a20-ir";
+   clocks = <_gates 6>, <_clk>;
+   clock-names = "apb", "ir";
+   interrupts = <0 5 1>;
+   reg = <0x01C21800 0x40>;
+   linux,rc-map-name = "rc-rc6-mce";
+};
-- 
1.9.3

--
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/


[PATCH v6 3/3] ARM: sunxi: Add IR controller support in DT on A20

2014-05-13 Thread Alexander Bersenev
This patch adds IR controller in A20 Device-Tree:
- Two IR devices found in A20 user manual
- Pins for two devices
- One IR device physically found on Cubieboard 2
- One IR device physically found on Cubietruck

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts |  6 ++
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts  |  6 ++
 arch/arm/boot/dts/sun7i-a20.dtsi| 31 +
 3 files changed, 43 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts 
b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
index feeff64..2564e8c 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
@@ -164,6 +164,12 @@
reg = <1>;
};
};
+
+   ir0: ir@01c21800 {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins_a>;
+   status = "okay";
+   };
};
 
leds {
diff --git a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts 
b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
index e288562..e375e89 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
@@ -232,6 +232,12 @@
reg = <1>;
};
};
+
+   ir0: ir@01c21800 {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins_a>;
+   status = "okay";
+   };
};
 
leds {
diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index 0ae2b77..40ded74 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -724,6 +724,19 @@
allwinner,drive = <2>;
allwinner,pull = <0>;
};
+
+   ir0_pins_a: ir0@0 {
+   allwinner,pins = "PB3","PB4";
+   allwinner,function = "ir0";
+   allwinner,drive = <0>;
+   allwinner,pull = <0>;
+   };
+   ir1_pins_a: ir1@0 {
+   allwinner,pins = "PB22","PB23";
+   allwinner,function = "ir1";
+   allwinner,drive = <0>;
+   allwinner,pull = <0>;
+   };
};
 
timer@01c20c00 {
@@ -937,5 +950,23 @@
#interrupt-cells = <3>;
interrupts = <1 9 0xf04>;
};
+
+   ir0: ir@01c21800 {
+   compatible = "allwinner,sun7i-a20-ir";
+   clocks = <_gates 6>, <_clk>;
+   clock-names = "apb", "ir";
+   interrupts = <0 5 4>;
+   reg = <0x01c21800 0x40>;
+   status = "disabled";
+   };
+
+   ir1: ir@01c21c00 {
+   compatible = "allwinner,sun7i-a20-ir";
+   clocks = <_gates 7>, <_clk>;
+   clock-names = "apb", "ir";
+   interrupts = <0 6 4>;
+   reg = <0x01C21c00 0x40>;
+   status = "disabled";
+   };
};
 };
-- 
1.9.3

--
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/


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

2014-05-13 Thread Alexander Bersenev
This patch adds driver for sunxi IR controller.
It is based on Alexsey Shestacov's work based on the original driver
supplied by Allwinner.

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 drivers/media/rc/Kconfig|  10 ++
 drivers/media/rc/Makefile   |   1 +
 drivers/media/rc/sunxi-ir.c | 309 
 3 files changed, 320 insertions(+)
 create mode 100644 drivers/media/rc/sunxi-ir.c

diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 8fbd377..9427fad 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -343,4 +343,14 @@ config RC_ST
 
 If you're not sure, select N here.
 
+config IR_SUNXI
+tristate "SUNXI IR remote control"
+depends on RC_CORE
+depends on ARCH_SUNXI
+---help---
+  Say Y if you want to use sunXi internal IR Controller
+
+  To compile this driver as a module, choose M here: the module will
+  be called sunxi-ir.
+
 endif #RC_DEVICES
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index f8b54ff..93cdbe9 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -32,4 +32,5 @@ 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_SUNXI) += sunxi-ir.o
 obj-$(CONFIG_IR_IMG) += img-ir/
diff --git a/drivers/media/rc/sunxi-ir.c b/drivers/media/rc/sunxi-ir.c
new file mode 100644
index 000..5a01305
--- /dev/null
+++ b/drivers/media/rc/sunxi-ir.c
@@ -0,0 +1,309 @@
+/*
+ * Driver for Allwinner sunXi IR controller
+ *
+ * Copyright (C) 2014 Alexsey Shestacov 
+ * Copyright (C) 2014 Alexander Bersenev 
+ *
+ * Based on sun5i-ir.c:
+ * Copyright (C) 2007-2012 Daniel Wang
+ * Allwinner Technology Co., 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define SUNXI_IR_DEV "sunxi-ir"
+
+/* Registers */
+/* IR Control */
+#define SUNXI_IR_CTL_REG  0x00
+/* Rx Config */
+#define SUNXI_IR_RXCTL_REG0x10
+/* Rx Data */
+#define SUNXI_IR_RXFIFO_REG   0x20
+/* Rx Interrupt Enable */
+#define SUNXI_IR_RXINT_REG0x2C
+/* Rx Interrupt Status */
+#define SUNXI_IR_RXSTA_REG0x30
+/* IR Sample Config */
+#define SUNXI_IR_CIR_REG  0x34
+
+/* IR_RXINT_REG Register fields */
+#define REG_RXINT_ROI_EN  BIT(0) /* Rx FIFO Overflow */
+#define REG_RXINT_RPEI_EN BIT(1) /* Rx Packet End */
+#define REG_RXINT_RAI_EN  BIT(4) /* Rx FIFO Data Available */
+/* Rx FIFO available byte level */
+#define REG_RXINT_RAL__MASK   (BIT(8)|BIT(9)|BIT(10)|BIT(11))
+#define REG_RXINT_RAL__SHIFT  8
+static inline uint32_t REG_RXINT_RAL(uint16_t val)
+{
+   return (val << REG_RXINT_RAL__SHIFT) & REG_RXINT_RAL__MASK;
+}
+
+/* Hardware supported fifo size */
+#define SUNXI_IR_FIFO_SIZE16
+/* How many messages in FIFO trigger IRQ */
+#define TRIGGER_LEVEL 8
+/* Required frequency for IR0 or IR1 clock in CIR mode */
+#define SUNXI_IR_BASE_CLK 800
+/* Frequency after IR internal divider  */
+#define SUNXI_IR_CLK  (SUNXI_IR_BASE_CLK / 64)
+/* Sample period in ns */
+#define SUNXI_IR_SAMPLE   (10ul / SUNXI_IR_CLK)
+/* Filter threshold in samples  */
+#define SUNXI_IR_RXFILT   1
+/* Idle Threshold in samples */
+#define SUNXI_IR_RXIDLE   20
+/* Time after which device stops sending data in ms */
+#define SUNXI_IR_TIMEOUT  120
+
+struct sunxi_ir {
+   spinlock_t  ir_lock;
+   struct rc_dev   *rc;
+   void __iomem*base;
+   int irq;
+   struct clk  *clk;
+   struct clk  *apb_clk;
+   const char  *map_name;
+};
+
+static irqreturn_t sunxi_ir_irq(int irqno, void *dev_id)
+{
+   unsigned long status;
+   unsigned char dt;
+   unsigned int cnt, rc;
+   struct sunxi_ir *ir = dev_id;
+   DEFINE_IR_RAW_EVENT(rawir);
+
+   spin_lock(>ir_lock);
+
+   status = readl(ir->base + SUNXI_IR_RXSTA_REG);
+
+   /* clean all pending statuses */
+   writel(status | 0xff, ir->base + SUNXI_IR_RXSTA_REG);
+
+   if (status & REG_RXINT_RAI_EN) {
+   /* How many messages in fifo */
+   rc  = (status >> 8) & 0x3f;
+   /* Sanity check */
+   rc = rc > SUNXI_IR_FIFO_SIZE ? SUNXI_IR_FIFO_SIZE : rc;
+   /* if we have data */
+   for (cnt = 0; cnt < r

[PATCH v6 0/3] ARM: sunxi: Add support for consumer infrared devices

2014-05-13 Thread Alexander Bersenev
This patch introduces Consumer IR(CIR) support for sunxi boards.

This is based on Alexsey Shestacov's work based on the original driver 
supplied by Allwinner.

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 

---
Changes since version 1: 
 - Fix timer memory leaks 
 - Fix race condition when driver unloads while interrupt handler is active
 - Support Cubieboard 2(need testing)

Changes since version 2:
- More reliable keydown events
- Documentation fixes
- Rename registers accurding to A20 user manual
- Remove some includes, order includes alphabetically
- Use BIT macro
- Typo fixes

Changes since version 3:
- Split the patch on smaller parts
- More documentation fixes
- Add clock-names in DT
- Use devm_clk_get function to get the clocks
- Removed gpios property from ir's DT
- Changed compatible from allwinner,sunxi-ir to allwinner,sun7i-a20-ir in DT
- Use spin_lock_irq instead spin_lock_irqsave in interrupt handler
- Add myself in the copyright ;)
- Coding style and indentation fixes

Changes since version 4:
- Try to fix indentation errors by sending patches with git send-mail

Changes since version 5:
- More indentation fixes
- Make patches pass checkpatch with --strict option
- Replaced magic numbers with defines(patch by Priit Laes)
- Fixed oops on loading(patch by Hans de Goede)



Alexander Bersenev (3):
  ARM: sunxi: Add documentation for sunxi consumer infrared devices
  ARM: sunxi: Add driver for sunxi IR controller
  ARM: sunxi: Add IR controller support in DT on A20

 .../devicetree/bindings/media/sunxi-ir.txt |  23 ++
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts|   6 +
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts |   6 +
 arch/arm/boot/dts/sun7i-a20.dtsi   |  31 +++
 drivers/media/rc/Kconfig   |  10 +
 drivers/media/rc/Makefile  |   1 +
 drivers/media/rc/sunxi-ir.c| 309 +
 7 files changed, 386 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt
 create mode 100644 drivers/media/rc/sunxi-ir.c

-- 
1.9.3
--
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/


[PATCH v6 0/3] ARM: sunxi: Add support for consumer infrared devices

2014-05-13 Thread Alexander Bersenev
This patch introduces Consumer IR(CIR) support for sunxi boards.

This is based on Alexsey Shestacov's work based on the original driver 
supplied by Allwinner.

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org

---
Changes since version 1: 
 - Fix timer memory leaks 
 - Fix race condition when driver unloads while interrupt handler is active
 - Support Cubieboard 2(need testing)

Changes since version 2:
- More reliable keydown events
- Documentation fixes
- Rename registers accurding to A20 user manual
- Remove some includes, order includes alphabetically
- Use BIT macro
- Typo fixes

Changes since version 3:
- Split the patch on smaller parts
- More documentation fixes
- Add clock-names in DT
- Use devm_clk_get function to get the clocks
- Removed gpios property from ir's DT
- Changed compatible from allwinner,sunxi-ir to allwinner,sun7i-a20-ir in DT
- Use spin_lock_irq instead spin_lock_irqsave in interrupt handler
- Add myself in the copyright ;)
- Coding style and indentation fixes

Changes since version 4:
- Try to fix indentation errors by sending patches with git send-mail

Changes since version 5:
- More indentation fixes
- Make patches pass checkpatch with --strict option
- Replaced magic numbers with defines(patch by Priit Laes)
- Fixed oops on loading(patch by Hans de Goede)



Alexander Bersenev (3):
  ARM: sunxi: Add documentation for sunxi consumer infrared devices
  ARM: sunxi: Add driver for sunxi IR controller
  ARM: sunxi: Add IR controller support in DT on A20

 .../devicetree/bindings/media/sunxi-ir.txt |  23 ++
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts|   6 +
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts |   6 +
 arch/arm/boot/dts/sun7i-a20.dtsi   |  31 +++
 drivers/media/rc/Kconfig   |  10 +
 drivers/media/rc/Makefile  |   1 +
 drivers/media/rc/sunxi-ir.c| 309 +
 7 files changed, 386 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt
 create mode 100644 drivers/media/rc/sunxi-ir.c

-- 
1.9.3
--
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/


[PATCH v6 3/3] ARM: sunxi: Add IR controller support in DT on A20

2014-05-13 Thread Alexander Bersenev
This patch adds IR controller in A20 Device-Tree:
- Two IR devices found in A20 user manual
- Pins for two devices
- One IR device physically found on Cubieboard 2
- One IR device physically found on Cubietruck

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts |  6 ++
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts  |  6 ++
 arch/arm/boot/dts/sun7i-a20.dtsi| 31 +
 3 files changed, 43 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts 
b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
index feeff64..2564e8c 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
@@ -164,6 +164,12 @@
reg = 1;
};
};
+
+   ir0: ir@01c21800 {
+   pinctrl-names = default;
+   pinctrl-0 = ir0_pins_a;
+   status = okay;
+   };
};
 
leds {
diff --git a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts 
b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
index e288562..e375e89 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
@@ -232,6 +232,12 @@
reg = 1;
};
};
+
+   ir0: ir@01c21800 {
+   pinctrl-names = default;
+   pinctrl-0 = ir0_pins_a;
+   status = okay;
+   };
};
 
leds {
diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index 0ae2b77..40ded74 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -724,6 +724,19 @@
allwinner,drive = 2;
allwinner,pull = 0;
};
+
+   ir0_pins_a: ir0@0 {
+   allwinner,pins = PB3,PB4;
+   allwinner,function = ir0;
+   allwinner,drive = 0;
+   allwinner,pull = 0;
+   };
+   ir1_pins_a: ir1@0 {
+   allwinner,pins = PB22,PB23;
+   allwinner,function = ir1;
+   allwinner,drive = 0;
+   allwinner,pull = 0;
+   };
};
 
timer@01c20c00 {
@@ -937,5 +950,23 @@
#interrupt-cells = 3;
interrupts = 1 9 0xf04;
};
+
+   ir0: ir@01c21800 {
+   compatible = allwinner,sun7i-a20-ir;
+   clocks = apb0_gates 6, ir0_clk;
+   clock-names = apb, ir;
+   interrupts = 0 5 4;
+   reg = 0x01c21800 0x40;
+   status = disabled;
+   };
+
+   ir1: ir@01c21c00 {
+   compatible = allwinner,sun7i-a20-ir;
+   clocks = apb0_gates 7, ir1_clk;
+   clock-names = apb, ir;
+   interrupts = 0 6 4;
+   reg = 0x01C21c00 0x40;
+   status = disabled;
+   };
};
 };
-- 
1.9.3

--
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/


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

2014-05-13 Thread Alexander Bersenev
This patch adds driver for sunxi IR controller.
It is based on Alexsey Shestacov's work based on the original driver
supplied by Allwinner.

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 drivers/media/rc/Kconfig|  10 ++
 drivers/media/rc/Makefile   |   1 +
 drivers/media/rc/sunxi-ir.c | 309 
 3 files changed, 320 insertions(+)
 create mode 100644 drivers/media/rc/sunxi-ir.c

diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 8fbd377..9427fad 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -343,4 +343,14 @@ config RC_ST
 
 If you're not sure, select N here.
 
+config IR_SUNXI
+tristate SUNXI IR remote control
+depends on RC_CORE
+depends on ARCH_SUNXI
+---help---
+  Say Y if you want to use sunXi internal IR Controller
+
+  To compile this driver as a module, choose M here: the module will
+  be called sunxi-ir.
+
 endif #RC_DEVICES
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index f8b54ff..93cdbe9 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -32,4 +32,5 @@ 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_SUNXI) += sunxi-ir.o
 obj-$(CONFIG_IR_IMG) += img-ir/
diff --git a/drivers/media/rc/sunxi-ir.c b/drivers/media/rc/sunxi-ir.c
new file mode 100644
index 000..5a01305
--- /dev/null
+++ b/drivers/media/rc/sunxi-ir.c
@@ -0,0 +1,309 @@
+/*
+ * Driver for Allwinner sunXi IR controller
+ *
+ * Copyright (C) 2014 Alexsey Shestacov wingr...@linux-sunxi.org
+ * Copyright (C) 2014 Alexander Bersenev b...@hackerdom.ru
+ *
+ * Based on sun5i-ir.c:
+ * Copyright (C) 2007-2012 Daniel Wang
+ * Allwinner Technology Co., Ltd. www.allwinnertech.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/clk.h
+#include linux/interrupt.h
+#include linux/module.h
+#include linux/of_platform.h
+#include media/rc-core.h
+
+#define SUNXI_IR_DEV sunxi-ir
+
+/* Registers */
+/* IR Control */
+#define SUNXI_IR_CTL_REG  0x00
+/* Rx Config */
+#define SUNXI_IR_RXCTL_REG0x10
+/* Rx Data */
+#define SUNXI_IR_RXFIFO_REG   0x20
+/* Rx Interrupt Enable */
+#define SUNXI_IR_RXINT_REG0x2C
+/* Rx Interrupt Status */
+#define SUNXI_IR_RXSTA_REG0x30
+/* IR Sample Config */
+#define SUNXI_IR_CIR_REG  0x34
+
+/* IR_RXINT_REG Register fields */
+#define REG_RXINT_ROI_EN  BIT(0) /* Rx FIFO Overflow */
+#define REG_RXINT_RPEI_EN BIT(1) /* Rx Packet End */
+#define REG_RXINT_RAI_EN  BIT(4) /* Rx FIFO Data Available */
+/* Rx FIFO available byte level */
+#define REG_RXINT_RAL__MASK   (BIT(8)|BIT(9)|BIT(10)|BIT(11))
+#define REG_RXINT_RAL__SHIFT  8
+static inline uint32_t REG_RXINT_RAL(uint16_t val)
+{
+   return (val  REG_RXINT_RAL__SHIFT)  REG_RXINT_RAL__MASK;
+}
+
+/* Hardware supported fifo size */
+#define SUNXI_IR_FIFO_SIZE16
+/* How many messages in FIFO trigger IRQ */
+#define TRIGGER_LEVEL 8
+/* Required frequency for IR0 or IR1 clock in CIR mode */
+#define SUNXI_IR_BASE_CLK 800
+/* Frequency after IR internal divider  */
+#define SUNXI_IR_CLK  (SUNXI_IR_BASE_CLK / 64)
+/* Sample period in ns */
+#define SUNXI_IR_SAMPLE   (10ul / SUNXI_IR_CLK)
+/* Filter threshold in samples  */
+#define SUNXI_IR_RXFILT   1
+/* Idle Threshold in samples */
+#define SUNXI_IR_RXIDLE   20
+/* Time after which device stops sending data in ms */
+#define SUNXI_IR_TIMEOUT  120
+
+struct sunxi_ir {
+   spinlock_t  ir_lock;
+   struct rc_dev   *rc;
+   void __iomem*base;
+   int irq;
+   struct clk  *clk;
+   struct clk  *apb_clk;
+   const char  *map_name;
+};
+
+static irqreturn_t sunxi_ir_irq(int irqno, void *dev_id)
+{
+   unsigned long status;
+   unsigned char dt;
+   unsigned int cnt, rc;
+   struct sunxi_ir *ir = dev_id;
+   DEFINE_IR_RAW_EVENT(rawir);
+
+   spin_lock(ir-ir_lock);
+
+   status = readl(ir-base + SUNXI_IR_RXSTA_REG);
+
+   /* clean all pending statuses */
+   writel(status | 0xff, ir-base + SUNXI_IR_RXSTA_REG);
+
+   if (status  REG_RXINT_RAI_EN) {
+   /* How many messages in fifo */
+   rc  = (status  8)  0x3f;
+   /* Sanity check */
+   rc = rc  SUNXI_IR_FIFO_SIZE

[PATCH v6 1/3] ARM: sunxi: Add documentation for sunxi consumer infrared devices

2014-05-13 Thread Alexander Bersenev
This patch adds documentation for Device-Tree bindings for sunxi IR
controller.

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 .../devicetree/bindings/media/sunxi-ir.txt | 23 ++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt

diff --git a/Documentation/devicetree/bindings/media/sunxi-ir.txt 
b/Documentation/devicetree/bindings/media/sunxi-ir.txt
new file mode 100644
index 000..014dd8b
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/sunxi-ir.txt
@@ -0,0 +1,23 @@
+Device-Tree bindings for SUNXI IR controller found in sunXi SoC family
+
+Required properties:
+- compatible   : should be allwinner,sun7i-a20-ir;
+- clocks   : list of clock specifiers, corresponding to
+ entries in clock-names property;
+- clock-names  : should contain apb and ir entries;
+- interrupts   : should contain IR IRQ number;
+- reg  : should contain IO map address for IR.
+
+Optional properties:
+- linux,rc-map-name : Remote control map name.
+
+Example:
+
+ir0: ir@01c21800 {
+   compatible = allwinner,sun7i-a20-ir;
+   clocks = apb0_gates 6, ir0_clk;
+   clock-names = apb, ir;
+   interrupts = 0 5 1;
+   reg = 0x01C21800 0x40;
+   linux,rc-map-name = rc-rc6-mce;
+};
-- 
1.9.3

--
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/


[PATCH v5 3/3] ARM: sunxi: Add IR controller support in DT on A20

2014-04-30 Thread Alexander Bersenev
This patch adds IR controller in A20 Device-Tree:
- Two IR devices found in A20 user manual
- Pins for two devices
- One IR device physically found on Cubieboard 2
- One IR device physically found on Cubietruck

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts |  6 ++
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts  |  6 ++
 arch/arm/boot/dts/sun7i-a20.dtsi| 31 +
 3 files changed, 43 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts 
b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
index feeff64..2564e8c 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
@@ -164,6 +164,12 @@
reg = <1>;
};
};
+
+   ir0: ir@01c21800 {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins_a>;
+   status = "okay";
+   };
};
 
leds {
diff --git a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts 
b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
index e288562..e375e89 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
@@ -232,6 +232,12 @@
reg = <1>;
};
};
+
+   ir0: ir@01c21800 {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins_a>;
+   status = "okay";
+   };
};
 
leds {
diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index 0ae2b77..bb655a5 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -724,6 +724,19 @@
allwinner,drive = <2>;
allwinner,pull = <0>;
};
+
+   ir0_pins_a: ir0@0 {
+   allwinner,pins = "PB3","PB4";
+   allwinner,function = "ir0";
+   allwinner,drive = <0>;
+   allwinner,pull = <0>;
+   };
+   ir1_pins_a: ir1@0 {
+   allwinner,pins = "PB22","PB23";
+   allwinner,function = "ir1";
+   allwinner,drive = <0>;
+   allwinner,pull = <0>;
+   };
};
 
timer@01c20c00 {
@@ -937,5 +950,23 @@
#interrupt-cells = <3>;
interrupts = <1 9 0xf04>;
};
+
+   ir0: ir@01c21800 {
+   compatible = "allwinner,sun7i-a20-ir";
+   clocks = <_gates 6>, <_clk>;
+   clock-names = "apb", "ir";
+   interrupts = <0 5 4>;
+   reg = <0x01c21800 0x40>;
+   status = "disabled";
+   };
+
+   ir1: ir@01c21c00 {
+   compatible = "allwinner,sun7i-a20-ir";
+   clocks = <_gates 7>, <_clk>;
+   clock-names = "apb", "ir";
+   interrupts = <0 6 4>;
+   reg = <0x01C21c00 0x40>;
+   status = "disabled";
+   };
};
 };
-- 
1.9.2

--
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/


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

2014-04-30 Thread Alexander Bersenev
This patch adds driver for sunxi IR controller.
It is based on Alexsey Shestacov's work based on the original driver
supplied by Allwinner.

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 drivers/media/rc/Kconfig|  10 ++
 drivers/media/rc/Makefile   |   1 +
 drivers/media/rc/sunxi-ir.c | 303 
 3 files changed, 314 insertions(+)
 create mode 100644 drivers/media/rc/sunxi-ir.c

diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 8fbd377..9427fad 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -343,4 +343,14 @@ config RC_ST
 
 If you're not sure, select N here.
 
+config IR_SUNXI
+tristate "SUNXI IR remote control"
+depends on RC_CORE
+depends on ARCH_SUNXI
+---help---
+  Say Y if you want to use sunXi internal IR Controller
+
+  To compile this driver as a module, choose M here: the module will
+  be called sunxi-ir.
+
 endif #RC_DEVICES
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index f8b54ff..93cdbe9 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -32,4 +32,5 @@ 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_SUNXI) += sunxi-ir.o
 obj-$(CONFIG_IR_IMG) += img-ir/
diff --git a/drivers/media/rc/sunxi-ir.c b/drivers/media/rc/sunxi-ir.c
new file mode 100644
index 000..f051d94
--- /dev/null
+++ b/drivers/media/rc/sunxi-ir.c
@@ -0,0 +1,303 @@
+/*
+ * Driver for Allwinner sunXi IR controller
+ *
+ * Copyright (C) 2014 Alexsey Shestacov 
+ * Copyright (C) 2014 Alexander Bersenev 
+ *
+ * Based on sun5i-ir.c:
+ * Copyright (C) 2007-2012 Daniel Wang
+ * Allwinner Technology Co., 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define SUNXI_IR_DEV "sunxi-ir"
+
+/* Registers */
+/* IR Control */
+#define SUNXI_IR_CTL_REG  0x00
+/* Rx Config */
+#define SUNXI_IR_RXCTL_REG0x10
+/* Rx Data */
+#define SUNXI_IR_RXFIFO_REG   0x20
+/* Rx Interrupt Enable */
+#define SUNXI_IR_RXINT_REG0x2C
+/* Rx Interrupt Status */
+#define SUNXI_IR_RXSTA_REG0x30
+/* IR Sample Config */
+#define SUNXI_IR_CIR_REG  0x34
+
+/* Bit Definition of IR_RXINTS_REG Register */
+#define SUNXI_IR_RXINTS_RXOF  BIT(0) /* Rx FIFO Overflow */
+#define SUNXI_IR_RXINTS_RXPE  BIT(1) /* Rx Packet End */
+#define SUNXI_IR_RXINTS_RXDA  BIT(4) /* Rx FIFO Data Available */
+/* Hardware supported fifo size */
+#define SUNXI_IR_FIFO_SIZE16
+/* How much messages in fifo triggers IRQ */
+#define SUNXI_IR_FIFO_TRIG8
+/* Required frequency for IR0 or IR1 clock in CIR mode */
+#define SUNXI_IR_BASE_CLK 800
+/* Frequency after IR internal divider  */
+#define SUNXI_IR_CLK  (SUNXI_IR_BASE_CLK / 64)
+/* Sample period in ns */
+#define SUNXI_IR_SAMPLE   (10ul / SUNXI_IR_CLK)
+/* Filter threshold in samples  */
+#define SUNXI_IR_RXFILT   1
+/* Idle Threshold in samples */
+#define SUNXI_IR_RXIDLE   20
+/* Time after which device stops sending data in ms */
+#define SUNXI_IR_TIMEOUT  120
+
+struct sunxi_ir {
+   spinlock_t  ir_lock;
+   struct rc_dev   *rc;
+   void __iomem*base;
+   int irq;
+   struct clk  *clk;
+   struct clk  *apb_clk;
+   const char  *map_name;
+};
+
+static irqreturn_t sunxi_ir_irq(int irqno, void *dev_id)
+{
+   unsigned long status;
+   unsigned char dt;
+   unsigned int cnt, rc;
+   struct sunxi_ir *ir = dev_id;
+   DEFINE_IR_RAW_EVENT(rawir);
+
+   spin_lock_irq(>ir_lock);
+
+   status = readl(ir->base + SUNXI_IR_RXSTA_REG);
+
+   /* clean all pending statuses */
+   writel(status | 0xff, ir->base + SUNXI_IR_RXSTA_REG);
+
+   if (status & SUNXI_IR_RXINTS_RXDA) {
+   /* How much messages in fifo */
+   rc  = (status >> 8) & 0x3f;
+   /* Sanity check */
+   rc = rc > SUNXI_IR_FIFO_SIZE ? SUNXI_IR_FIFO_SIZE : rc;
+   /* if we have data */
+   for (cnt = 0; cnt < rc; cnt++) {
+   /* for each bit in fifo */
+   dt = readb(ir->base + SUNXI_IR_RXFIFO_REG);
+   rawir.pulse = (dt & 0x80) != 0;
+ 

[PATCH v5 1/3] ARM: sunxi: Add documentation for sunxi consumer infrared devices

2014-04-30 Thread Alexander Bersenev
This patch adds documentation for Device-Tree bindings for sunxi IR
controller.

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 
---
 .../devicetree/bindings/media/sunxi-ir.txt | 23 ++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt

diff --git a/Documentation/devicetree/bindings/media/sunxi-ir.txt 
b/Documentation/devicetree/bindings/media/sunxi-ir.txt
new file mode 100644
index 000..d502cf4
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/sunxi-ir.txt
@@ -0,0 +1,23 @@
+Device-Tree bindings for SUNXI IR controller found in sunXi SoC family
+
+Required properties:
+- compatible   : should be "allwinner,sun7i-a20-ir";
+- clocks   : list of clock specifiers, corresponding to
+ entries in clock-names property;
+- clock-names  : should contain "apb0_ir0" and "ir0" entries;
+- interrupts   : should contain IR IRQ number;
+- reg  : should contain IO map address for IR.
+
+Optional properties:
+- linux,rc-map-name : Remote control map name.
+
+Example:
+
+ir0: ir@01c21800 {
+   compatible = "allwinner,sun7i-a20-ir";
+   clocks = <_gates 6>, <_clk>;
+   clock-names = "apb0_ir0", "ir0";
+   interrupts = <0 5 1>;
+   reg = <0x01C21800 0x40>;
+   linux,rc-map-name = "rc-rc6-mce";
+};
-- 
1.9.2

--
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/


[PATCH v5 0/3] ARM: sunxi: Add support for consumer infrared devices

2014-04-30 Thread Alexander Bersenev
This patch introduces Consumer IR(CIR) support for sunxi boards.

This is based on Alexsey Shestacov's work based on the original driver 
supplied by Allwinner.

Signed-off-by: Alexander Bersenev 
Signed-off-by: Alexsey Shestacov 

---
Changes since version 1: 
 - Fix timer memory leaks 
 - Fix race condition when driver unloads while interrupt handler is active
 - Support Cubieboard 2(need testing)

Changes since version 2:
- More reliable keydown events
- Documentation fixes
- Rename registers accurding to A20 user manual
- Remove some includes, order includes alphabetically
- Use BIT macro
- Typo fixes

Changes since version 3:
- Split the patch on smaller parts
- More documentation fixes
- Add clock-names in DT
- Use devm_clk_get function to get the clocks
- Removed gpios property from ir's DT
- Changed compatible from allwinner,sunxi-ir to allwinner,sun7i-a20-ir in DT
- Use spin_lock_irq instead spin_lock_irqsave in interrupt handler
- Add myself in the copyright ;)
- Coding style and indentation fixes

Changes since version 4:
- Try to fix indentation errors by sending patches with git send-mail

Alexander Bersenev (3):
  ARM: sunxi: Add documentation for sunxi consumer infrared devices
  ARM: sunxi: Add driver for sunxi IR controller
  ARM: sunxi: Add IR controller support in DT on A20

 .../devicetree/bindings/media/sunxi-ir.txt |  23 ++
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts|   6 +
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts |   6 +
 arch/arm/boot/dts/sun7i-a20.dtsi   |  31 +++
 drivers/media/rc/Kconfig   |  10 +
 drivers/media/rc/Makefile  |   1 +
 drivers/media/rc/sunxi-ir.c| 303 +
 7 files changed, 380 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt
 create mode 100644 drivers/media/rc/sunxi-ir.c

-- 
1.9.2

--
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/


[PATCH v5 0/3] ARM: sunxi: Add support for consumer infrared devices

2014-04-30 Thread Alexander Bersenev
This patch introduces Consumer IR(CIR) support for sunxi boards.

This is based on Alexsey Shestacov's work based on the original driver 
supplied by Allwinner.

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org

---
Changes since version 1: 
 - Fix timer memory leaks 
 - Fix race condition when driver unloads while interrupt handler is active
 - Support Cubieboard 2(need testing)

Changes since version 2:
- More reliable keydown events
- Documentation fixes
- Rename registers accurding to A20 user manual
- Remove some includes, order includes alphabetically
- Use BIT macro
- Typo fixes

Changes since version 3:
- Split the patch on smaller parts
- More documentation fixes
- Add clock-names in DT
- Use devm_clk_get function to get the clocks
- Removed gpios property from ir's DT
- Changed compatible from allwinner,sunxi-ir to allwinner,sun7i-a20-ir in DT
- Use spin_lock_irq instead spin_lock_irqsave in interrupt handler
- Add myself in the copyright ;)
- Coding style and indentation fixes

Changes since version 4:
- Try to fix indentation errors by sending patches with git send-mail

Alexander Bersenev (3):
  ARM: sunxi: Add documentation for sunxi consumer infrared devices
  ARM: sunxi: Add driver for sunxi IR controller
  ARM: sunxi: Add IR controller support in DT on A20

 .../devicetree/bindings/media/sunxi-ir.txt |  23 ++
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts|   6 +
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts |   6 +
 arch/arm/boot/dts/sun7i-a20.dtsi   |  31 +++
 drivers/media/rc/Kconfig   |  10 +
 drivers/media/rc/Makefile  |   1 +
 drivers/media/rc/sunxi-ir.c| 303 +
 7 files changed, 380 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt
 create mode 100644 drivers/media/rc/sunxi-ir.c

-- 
1.9.2

--
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/


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

2014-04-30 Thread Alexander Bersenev
This patch adds driver for sunxi IR controller.
It is based on Alexsey Shestacov's work based on the original driver
supplied by Allwinner.

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 drivers/media/rc/Kconfig|  10 ++
 drivers/media/rc/Makefile   |   1 +
 drivers/media/rc/sunxi-ir.c | 303 
 3 files changed, 314 insertions(+)
 create mode 100644 drivers/media/rc/sunxi-ir.c

diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 8fbd377..9427fad 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -343,4 +343,14 @@ config RC_ST
 
 If you're not sure, select N here.
 
+config IR_SUNXI
+tristate SUNXI IR remote control
+depends on RC_CORE
+depends on ARCH_SUNXI
+---help---
+  Say Y if you want to use sunXi internal IR Controller
+
+  To compile this driver as a module, choose M here: the module will
+  be called sunxi-ir.
+
 endif #RC_DEVICES
diff --git a/drivers/media/rc/Makefile b/drivers/media/rc/Makefile
index f8b54ff..93cdbe9 100644
--- a/drivers/media/rc/Makefile
+++ b/drivers/media/rc/Makefile
@@ -32,4 +32,5 @@ 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_SUNXI) += sunxi-ir.o
 obj-$(CONFIG_IR_IMG) += img-ir/
diff --git a/drivers/media/rc/sunxi-ir.c b/drivers/media/rc/sunxi-ir.c
new file mode 100644
index 000..f051d94
--- /dev/null
+++ b/drivers/media/rc/sunxi-ir.c
@@ -0,0 +1,303 @@
+/*
+ * Driver for Allwinner sunXi IR controller
+ *
+ * Copyright (C) 2014 Alexsey Shestacov wingr...@linux-sunxi.org
+ * Copyright (C) 2014 Alexander Bersenev b...@hackerdom.ru
+ *
+ * Based on sun5i-ir.c:
+ * Copyright (C) 2007-2012 Daniel Wang
+ * Allwinner Technology Co., Ltd. www.allwinnertech.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include linux/clk.h
+#include linux/interrupt.h
+#include linux/module.h
+#include linux/of_platform.h
+#include media/rc-core.h
+
+#define SUNXI_IR_DEV sunxi-ir
+
+/* Registers */
+/* IR Control */
+#define SUNXI_IR_CTL_REG  0x00
+/* Rx Config */
+#define SUNXI_IR_RXCTL_REG0x10
+/* Rx Data */
+#define SUNXI_IR_RXFIFO_REG   0x20
+/* Rx Interrupt Enable */
+#define SUNXI_IR_RXINT_REG0x2C
+/* Rx Interrupt Status */
+#define SUNXI_IR_RXSTA_REG0x30
+/* IR Sample Config */
+#define SUNXI_IR_CIR_REG  0x34
+
+/* Bit Definition of IR_RXINTS_REG Register */
+#define SUNXI_IR_RXINTS_RXOF  BIT(0) /* Rx FIFO Overflow */
+#define SUNXI_IR_RXINTS_RXPE  BIT(1) /* Rx Packet End */
+#define SUNXI_IR_RXINTS_RXDA  BIT(4) /* Rx FIFO Data Available */
+/* Hardware supported fifo size */
+#define SUNXI_IR_FIFO_SIZE16
+/* How much messages in fifo triggers IRQ */
+#define SUNXI_IR_FIFO_TRIG8
+/* Required frequency for IR0 or IR1 clock in CIR mode */
+#define SUNXI_IR_BASE_CLK 800
+/* Frequency after IR internal divider  */
+#define SUNXI_IR_CLK  (SUNXI_IR_BASE_CLK / 64)
+/* Sample period in ns */
+#define SUNXI_IR_SAMPLE   (10ul / SUNXI_IR_CLK)
+/* Filter threshold in samples  */
+#define SUNXI_IR_RXFILT   1
+/* Idle Threshold in samples */
+#define SUNXI_IR_RXIDLE   20
+/* Time after which device stops sending data in ms */
+#define SUNXI_IR_TIMEOUT  120
+
+struct sunxi_ir {
+   spinlock_t  ir_lock;
+   struct rc_dev   *rc;
+   void __iomem*base;
+   int irq;
+   struct clk  *clk;
+   struct clk  *apb_clk;
+   const char  *map_name;
+};
+
+static irqreturn_t sunxi_ir_irq(int irqno, void *dev_id)
+{
+   unsigned long status;
+   unsigned char dt;
+   unsigned int cnt, rc;
+   struct sunxi_ir *ir = dev_id;
+   DEFINE_IR_RAW_EVENT(rawir);
+
+   spin_lock_irq(ir-ir_lock);
+
+   status = readl(ir-base + SUNXI_IR_RXSTA_REG);
+
+   /* clean all pending statuses */
+   writel(status | 0xff, ir-base + SUNXI_IR_RXSTA_REG);
+
+   if (status  SUNXI_IR_RXINTS_RXDA) {
+   /* How much messages in fifo */
+   rc  = (status  8)  0x3f;
+   /* Sanity check */
+   rc = rc  SUNXI_IR_FIFO_SIZE ? SUNXI_IR_FIFO_SIZE : rc;
+   /* if we have data */
+   for (cnt = 0; cnt  rc; cnt++) {
+   /* for each bit in fifo */
+   dt = readb(ir-base + SUNXI_IR_RXFIFO_REG

[PATCH v5 3/3] ARM: sunxi: Add IR controller support in DT on A20

2014-04-30 Thread Alexander Bersenev
This patch adds IR controller in A20 Device-Tree:
- Two IR devices found in A20 user manual
- Pins for two devices
- One IR device physically found on Cubieboard 2
- One IR device physically found on Cubietruck

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 arch/arm/boot/dts/sun7i-a20-cubieboard2.dts |  6 ++
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts  |  6 ++
 arch/arm/boot/dts/sun7i-a20.dtsi| 31 +
 3 files changed, 43 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts 
b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
index feeff64..2564e8c 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubieboard2.dts
@@ -164,6 +164,12 @@
reg = 1;
};
};
+
+   ir0: ir@01c21800 {
+   pinctrl-names = default;
+   pinctrl-0 = ir0_pins_a;
+   status = okay;
+   };
};
 
leds {
diff --git a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts 
b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
index e288562..e375e89 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
@@ -232,6 +232,12 @@
reg = 1;
};
};
+
+   ir0: ir@01c21800 {
+   pinctrl-names = default;
+   pinctrl-0 = ir0_pins_a;
+   status = okay;
+   };
};
 
leds {
diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index 0ae2b77..bb655a5 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -724,6 +724,19 @@
allwinner,drive = 2;
allwinner,pull = 0;
};
+
+   ir0_pins_a: ir0@0 {
+   allwinner,pins = PB3,PB4;
+   allwinner,function = ir0;
+   allwinner,drive = 0;
+   allwinner,pull = 0;
+   };
+   ir1_pins_a: ir1@0 {
+   allwinner,pins = PB22,PB23;
+   allwinner,function = ir1;
+   allwinner,drive = 0;
+   allwinner,pull = 0;
+   };
};
 
timer@01c20c00 {
@@ -937,5 +950,23 @@
#interrupt-cells = 3;
interrupts = 1 9 0xf04;
};
+
+   ir0: ir@01c21800 {
+   compatible = allwinner,sun7i-a20-ir;
+   clocks = apb0_gates 6, ir0_clk;
+   clock-names = apb, ir;
+   interrupts = 0 5 4;
+   reg = 0x01c21800 0x40;
+   status = disabled;
+   };
+
+   ir1: ir@01c21c00 {
+   compatible = allwinner,sun7i-a20-ir;
+   clocks = apb0_gates 7, ir1_clk;
+   clock-names = apb, ir;
+   interrupts = 0 6 4;
+   reg = 0x01C21c00 0x40;
+   status = disabled;
+   };
};
 };
-- 
1.9.2

--
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/


[PATCH v5 1/3] ARM: sunxi: Add documentation for sunxi consumer infrared devices

2014-04-30 Thread Alexander Bersenev
This patch adds documentation for Device-Tree bindings for sunxi IR
controller.

Signed-off-by: Alexander Bersenev b...@hackerdom.ru
Signed-off-by: Alexsey Shestacov wingr...@linux-sunxi.org
---
 .../devicetree/bindings/media/sunxi-ir.txt | 23 ++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/media/sunxi-ir.txt

diff --git a/Documentation/devicetree/bindings/media/sunxi-ir.txt 
b/Documentation/devicetree/bindings/media/sunxi-ir.txt
new file mode 100644
index 000..d502cf4
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/sunxi-ir.txt
@@ -0,0 +1,23 @@
+Device-Tree bindings for SUNXI IR controller found in sunXi SoC family
+
+Required properties:
+- compatible   : should be allwinner,sun7i-a20-ir;
+- clocks   : list of clock specifiers, corresponding to
+ entries in clock-names property;
+- clock-names  : should contain apb0_ir0 and ir0 entries;
+- interrupts   : should contain IR IRQ number;
+- reg  : should contain IO map address for IR.
+
+Optional properties:
+- linux,rc-map-name : Remote control map name.
+
+Example:
+
+ir0: ir@01c21800 {
+   compatible = allwinner,sun7i-a20-ir;
+   clocks = apb0_gates 6, ir0_clk;
+   clock-names = apb0_ir0, ir0;
+   interrupts = 0 5 1;
+   reg = 0x01C21800 0x40;
+   linux,rc-map-name = rc-rc6-mce;
+};
-- 
1.9.2

--
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/