[linux-sunxi] Re: [PATCH v4 02/03] ARM: sunxi: Add driver for sunxi IR controller

2014-04-30 Thread Александр Берсенев
[PATCH v4 02/03] ARM: sunxi: Add driver for sunxi IR controller

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

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);
+ rawir.pulse = (dt  0x80) != 0;
+ rawir.duration = (dt  0x7f) * SUNXI_IR_SAMPLE;
+ ir_raw_event_store_with_filter(ir-rc, rawir);
+ }
+ }
+
+ if (status  SUNXI_IR_RXINTS_RXOF)
+ ir_raw_event_reset(ir-rc);
+ else if (status  SUNXI_IR_RXINTS_RXPE) {
+ ir_raw_event_set_idle(ir-rc, true);
+ ir_raw_event_handle(ir-rc);
+ }
+
+ spin_unlock_irq(ir-ir_lock);
+
+ return IRQ_HANDLED;
+}
+
+
+static int sunxi_ir_probe(struct 

[linux-sunxi] Re: [PATCH v4 02/03] ARM: sunxi: Add driver for sunxi IR controller

2014-04-30 Thread Mauro Carvalho Chehab
Em Wed, 30 Apr 2014 03:58:18 -0700 (PDT)
Александр Берсенев b...@hackerdom.ru escreveu:

 [PATCH v4 02/03] ARM: sunxi: Add driver for sunxi IR controller
 
 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
 
 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;
 +};

Still badly indented. Maybe your emailer is mangling whitespaces.

The best is to use git send-email to send the patches.

Also, please c/c linux-media ML for the entire patch series, as, in general,
we generally merge all patches via one tree (typically, the tree to where the
real driver will be merged - in this case, the media tree), after getting
the needed acks from DT and arm subarch maintainers (when applicable).

I'll do a better review after the whitespace fixups.

Regards,
Mauro

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