Re: [PATCH v6 6/8] input: touchscreen: imx25 tcq driver

2015-02-26 Thread Markus Pargmann
Hi,

On Mon, Feb 02, 2015 at 09:51:34AM -0800, Dmitry Torokhov wrote:
> On Mon, Feb 02, 2015 at 05:05:39PM +0100, Markus Pargmann wrote:
> > Hi,
> > 
> > On Fri, Jan 30, 2015 at 10:57:21AM -0800, Dmitry Torokhov wrote:
> > > On Thu, Jan 29, 2015 at 07:56:40PM +0530, Varka Bhadram wrote:
> > > > Hi,
> > > > 
> > > > On Thursday 29 January 2015 07:39 PM, Markus Pargmann wrote:
> > > > >This is a driver for the imx25 ADC/TSC module. It controls the
> > > > >touchscreen conversion queue and creates a touchscreen input device.
> > > > >The driver currently only supports 4 wire touchscreens. The driver uses
> > > > >a simple conversion queue of precharge, touch detection, X measurement,
> > > > >Y measurement, precharge and another touch detection.
> > > > >
> > > > >This driver uses the regmap from the parent to setup some touch 
> > > > >specific
> > > > >settings in the core driver and setup a idle configuration with touch
> > > > >detection.
> > > > >
> > > > >Signed-off-by: Markus Pargmann 
> > > > >Signed-off-by: Denis Carikli 
> > > > >Acked-by: Dmitry Torokhov 
> > > > >Signed-off-by: Markus Pargmann 
> > > > >---
> > > > >  drivers/input/touchscreen/Kconfig |   6 +
> > > > >  drivers/input/touchscreen/Makefile|   1 +
> > > > >  drivers/input/touchscreen/fsl-imx25-tcq.c | 587 
> > > > > ++
> > > > >  3 files changed, 594 insertions(+)
> > > > >  create mode 100644 drivers/input/touchscreen/fsl-imx25-tcq.c
> > > > >
> > > > (...)
> > > > 
> > > > >+  ret = request_threaded_irq(priv->irq, mx25_tcq_irq, 
> > > > >mx25_tcq_irq_thread,
> > > > >+ IRQF_ONESHOT, pdev->name, priv);
> > > > 
> > > > We can use devres API for request_thread_irq()...
> > > > 
> > > > >+  if (ret) {
> > > > >+  dev_err(dev, "Failed requesting IRQ\n");
> > > > >+  goto err_clk_unprepare;
> > > > >+  }
> > > > >+
> > > > >+  ret = mx25_tcq_init(priv);
> > > > >+  if (ret) {
> > > > >+  dev_err(dev, "Failed to init tcq\n");
> > > > >+  goto error_free_irq;
> > > > >+  }
> > > > >+
> > > > >+  platform_set_drvdata(pdev, priv);
> > > > >+
> > > > >+  return 0;
> > > > >+
> > > > >+error_free_irq:
> > > > >+  free_irq(priv->irq, priv);
> > > > 
> > > > This is not required if we use devres API
> > > 
> > > Yes it does - you do not really want to stop clocks in the middle of
> > > servicing interrupt.
> > 
> > Thanks, I missed the clocks. I will not use devm here then.
> 
> Actually, you still can if you move clock enabling/disabling and
> mx25_tcq_init() into input_dev->open() and ->close() callbacks. Close
> will be called during input device un-registration which happens (given
> your current sequence) after freeing irq by devm.

Thank you. I now moved that code into open() and close(), replaced the
irq_request() with devm_irq_request. mx25_tcq_remove() is gone now.

> 
> By the way, I used my old @vmware address by accident. Can you please
> replace the original acked by with:
> 
> Acked-by: Dmitry Torokhov 

Replaced it.

Thanks,

Markus

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


signature.asc
Description: Digital signature


Re: [PATCH v6 6/8] input: touchscreen: imx25 tcq driver

2015-02-02 Thread Dmitry Torokhov
On Mon, Feb 02, 2015 at 05:05:39PM +0100, Markus Pargmann wrote:
> Hi,
> 
> On Fri, Jan 30, 2015 at 10:57:21AM -0800, Dmitry Torokhov wrote:
> > On Thu, Jan 29, 2015 at 07:56:40PM +0530, Varka Bhadram wrote:
> > > Hi,
> > > 
> > > On Thursday 29 January 2015 07:39 PM, Markus Pargmann wrote:
> > > >This is a driver for the imx25 ADC/TSC module. It controls the
> > > >touchscreen conversion queue and creates a touchscreen input device.
> > > >The driver currently only supports 4 wire touchscreens. The driver uses
> > > >a simple conversion queue of precharge, touch detection, X measurement,
> > > >Y measurement, precharge and another touch detection.
> > > >
> > > >This driver uses the regmap from the parent to setup some touch specific
> > > >settings in the core driver and setup a idle configuration with touch
> > > >detection.
> > > >
> > > >Signed-off-by: Markus Pargmann 
> > > >Signed-off-by: Denis Carikli 
> > > >Acked-by: Dmitry Torokhov 
> > > >Signed-off-by: Markus Pargmann 
> > > >---
> > > >  drivers/input/touchscreen/Kconfig |   6 +
> > > >  drivers/input/touchscreen/Makefile|   1 +
> > > >  drivers/input/touchscreen/fsl-imx25-tcq.c | 587 
> > > > ++
> > > >  3 files changed, 594 insertions(+)
> > > >  create mode 100644 drivers/input/touchscreen/fsl-imx25-tcq.c
> > > >
> > > (...)
> > > 
> > > >+ret = request_threaded_irq(priv->irq, mx25_tcq_irq, 
> > > >mx25_tcq_irq_thread,
> > > >+   IRQF_ONESHOT, pdev->name, priv);
> > > 
> > > We can use devres API for request_thread_irq()...
> > > 
> > > >+if (ret) {
> > > >+dev_err(dev, "Failed requesting IRQ\n");
> > > >+goto err_clk_unprepare;
> > > >+}
> > > >+
> > > >+ret = mx25_tcq_init(priv);
> > > >+if (ret) {
> > > >+dev_err(dev, "Failed to init tcq\n");
> > > >+goto error_free_irq;
> > > >+}
> > > >+
> > > >+platform_set_drvdata(pdev, priv);
> > > >+
> > > >+return 0;
> > > >+
> > > >+error_free_irq:
> > > >+free_irq(priv->irq, priv);
> > > 
> > > This is not required if we use devres API
> > 
> > Yes it does - you do not really want to stop clocks in the middle of
> > servicing interrupt.
> 
> Thanks, I missed the clocks. I will not use devm here then.

Actually, you still can if you move clock enabling/disabling and
mx25_tcq_init() into input_dev->open() and ->close() callbacks. Close
will be called during input device un-registration which happens (given
your current sequence) after freeing irq by devm.

By the way, I used my old @vmware address by accident. Can you please
replace the original acked by with:

Acked-by: Dmitry Torokhov 

Thanks.

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


Re: [PATCH v6 6/8] input: touchscreen: imx25 tcq driver

2015-02-02 Thread Markus Pargmann
Hi,

On Fri, Jan 30, 2015 at 10:57:21AM -0800, Dmitry Torokhov wrote:
> On Thu, Jan 29, 2015 at 07:56:40PM +0530, Varka Bhadram wrote:
> > Hi,
> > 
> > On Thursday 29 January 2015 07:39 PM, Markus Pargmann wrote:
> > >This is a driver for the imx25 ADC/TSC module. It controls the
> > >touchscreen conversion queue and creates a touchscreen input device.
> > >The driver currently only supports 4 wire touchscreens. The driver uses
> > >a simple conversion queue of precharge, touch detection, X measurement,
> > >Y measurement, precharge and another touch detection.
> > >
> > >This driver uses the regmap from the parent to setup some touch specific
> > >settings in the core driver and setup a idle configuration with touch
> > >detection.
> > >
> > >Signed-off-by: Markus Pargmann 
> > >Signed-off-by: Denis Carikli 
> > >Acked-by: Dmitry Torokhov 
> > >Signed-off-by: Markus Pargmann 
> > >---
> > >  drivers/input/touchscreen/Kconfig |   6 +
> > >  drivers/input/touchscreen/Makefile|   1 +
> > >  drivers/input/touchscreen/fsl-imx25-tcq.c | 587 
> > > ++
> > >  3 files changed, 594 insertions(+)
> > >  create mode 100644 drivers/input/touchscreen/fsl-imx25-tcq.c
> > >
> > (...)
> > 
> > >+  ret = request_threaded_irq(priv->irq, mx25_tcq_irq, mx25_tcq_irq_thread,
> > >+ IRQF_ONESHOT, pdev->name, priv);
> > 
> > We can use devres API for request_thread_irq()...
> > 
> > >+  if (ret) {
> > >+  dev_err(dev, "Failed requesting IRQ\n");
> > >+  goto err_clk_unprepare;
> > >+  }
> > >+
> > >+  ret = mx25_tcq_init(priv);
> > >+  if (ret) {
> > >+  dev_err(dev, "Failed to init tcq\n");
> > >+  goto error_free_irq;
> > >+  }
> > >+
> > >+  platform_set_drvdata(pdev, priv);
> > >+
> > >+  return 0;
> > >+
> > >+error_free_irq:
> > >+  free_irq(priv->irq, priv);
> > 
> > This is not required if we use devres API
> 
> Yes it does - you do not really want to stop clocks in the middle of
> servicing interrupt.

Thanks, I missed the clocks. I will not use devm here then.

For the gcq (ADC) driver, it would still works to use devm_request_irq as the
interrupt can only trigger when the user requested an ADC conversion. So as
soon as the device is unregistered from the IIO subsystem, there should
not be any interrupts. However I would like to keep free_irq in the gcq
driver as well. Unexpected interrupts wouldn't be a problem and
especially if the driver is extended for continous conversion in the
future, this may be better.

Best regards,

Markus

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


signature.asc
Description: Digital signature


Re: [PATCH v6 6/8] input: touchscreen: imx25 tcq driver

2015-01-30 Thread Dmitry Torokhov
On Thu, Jan 29, 2015 at 07:56:40PM +0530, Varka Bhadram wrote:
> Hi,
> 
> On Thursday 29 January 2015 07:39 PM, Markus Pargmann wrote:
> >This is a driver for the imx25 ADC/TSC module. It controls the
> >touchscreen conversion queue and creates a touchscreen input device.
> >The driver currently only supports 4 wire touchscreens. The driver uses
> >a simple conversion queue of precharge, touch detection, X measurement,
> >Y measurement, precharge and another touch detection.
> >
> >This driver uses the regmap from the parent to setup some touch specific
> >settings in the core driver and setup a idle configuration with touch
> >detection.
> >
> >Signed-off-by: Markus Pargmann 
> >Signed-off-by: Denis Carikli 
> >Acked-by: Dmitry Torokhov 
> >Signed-off-by: Markus Pargmann 
> >---
> >  drivers/input/touchscreen/Kconfig |   6 +
> >  drivers/input/touchscreen/Makefile|   1 +
> >  drivers/input/touchscreen/fsl-imx25-tcq.c | 587 
> > ++
> >  3 files changed, 594 insertions(+)
> >  create mode 100644 drivers/input/touchscreen/fsl-imx25-tcq.c
> >
> (...)
> 
> >+ret = request_threaded_irq(priv->irq, mx25_tcq_irq, mx25_tcq_irq_thread,
> >+   IRQF_ONESHOT, pdev->name, priv);
> 
> We can use devres API for request_thread_irq()...
> 
> >+if (ret) {
> >+dev_err(dev, "Failed requesting IRQ\n");
> >+goto err_clk_unprepare;
> >+}
> >+
> >+ret = mx25_tcq_init(priv);
> >+if (ret) {
> >+dev_err(dev, "Failed to init tcq\n");
> >+goto error_free_irq;
> >+}
> >+
> >+platform_set_drvdata(pdev, priv);
> >+
> >+return 0;
> >+
> >+error_free_irq:
> >+free_irq(priv->irq, priv);
> 
> This is not required if we use devres API

Yes it does - you do not really want to stop clocks in the middle of
servicing interrupt.

Thanks.

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


Re: [PATCH v6 6/8] input: touchscreen: imx25 tcq driver

2015-01-29 Thread Varka Bhadram

Hi,

On Thursday 29 January 2015 07:39 PM, Markus Pargmann wrote:

This is a driver for the imx25 ADC/TSC module. It controls the
touchscreen conversion queue and creates a touchscreen input device.
The driver currently only supports 4 wire touchscreens. The driver uses
a simple conversion queue of precharge, touch detection, X measurement,
Y measurement, precharge and another touch detection.

This driver uses the regmap from the parent to setup some touch specific
settings in the core driver and setup a idle configuration with touch
detection.

Signed-off-by: Markus Pargmann 
Signed-off-by: Denis Carikli 
Acked-by: Dmitry Torokhov 
Signed-off-by: Markus Pargmann 
---
  drivers/input/touchscreen/Kconfig |   6 +
  drivers/input/touchscreen/Makefile|   1 +
  drivers/input/touchscreen/fsl-imx25-tcq.c | 587 ++
  3 files changed, 594 insertions(+)
  create mode 100644 drivers/input/touchscreen/fsl-imx25-tcq.c


(...)


+   ret = request_threaded_irq(priv->irq, mx25_tcq_irq, mx25_tcq_irq_thread,
+  IRQF_ONESHOT, pdev->name, priv);


We can use devres API for request_thread_irq()...


+   if (ret) {
+   dev_err(dev, "Failed requesting IRQ\n");
+   goto err_clk_unprepare;
+   }
+
+   ret = mx25_tcq_init(priv);
+   if (ret) {
+   dev_err(dev, "Failed to init tcq\n");
+   goto error_free_irq;
+   }
+
+   platform_set_drvdata(pdev, priv);
+
+   return 0;
+
+error_free_irq:
+   free_irq(priv->irq, priv);


This is not required if we use devres API


+err_clk_unprepare:
+   clk_disable_unprepare(priv->clk);
+   return ret;
+}
+
+static int mx25_tcq_remove(struct platform_device *pdev)
+{
+   struct mx25_tcq_priv *priv = platform_get_drvdata(pdev);
+
+   free_irq(priv->irq, priv);


This also..


--
Regards,
Varka Bhadram.

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


[PATCH v6 6/8] input: touchscreen: imx25 tcq driver

2015-01-29 Thread Markus Pargmann
This is a driver for the imx25 ADC/TSC module. It controls the
touchscreen conversion queue and creates a touchscreen input device.
The driver currently only supports 4 wire touchscreens. The driver uses
a simple conversion queue of precharge, touch detection, X measurement,
Y measurement, precharge and another touch detection.

This driver uses the regmap from the parent to setup some touch specific
settings in the core driver and setup a idle configuration with touch
detection.

Signed-off-by: Markus Pargmann 
Signed-off-by: Denis Carikli 
Acked-by: Dmitry Torokhov 
Signed-off-by: Markus Pargmann 
---
 drivers/input/touchscreen/Kconfig |   6 +
 drivers/input/touchscreen/Makefile|   1 +
 drivers/input/touchscreen/fsl-imx25-tcq.c | 587 ++
 3 files changed, 594 insertions(+)
 create mode 100644 drivers/input/touchscreen/fsl-imx25-tcq.c

diff --git a/drivers/input/touchscreen/Kconfig 
b/drivers/input/touchscreen/Kconfig
index 58917525126e..f1534a0cd23f 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -748,6 +748,12 @@ config TOUCHSCREEN_USB_COMPOSITE
  To compile this driver as a module, choose M here: the
  module will be called usbtouchscreen.
 
+config TOUCHSCREEN_MX25
+   tristate "Freescale i.MX25 touchscreen input driver"
+   depends on MFD_MX25_TSADC
+   help
+ Enable support for touchscreen connected to your i.MX25.
+
 config TOUCHSCREEN_MC13783
tristate "Freescale MC13783 touchscreen input driver"
depends on MFD_MC13XXX
diff --git a/drivers/input/touchscreen/Makefile 
b/drivers/input/touchscreen/Makefile
index 0242fea2102a..bbb55a69c33c 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -41,6 +41,7 @@ obj-$(CONFIG_TOUCHSCREEN_INEXIO)  += inexio.o
 obj-$(CONFIG_TOUCHSCREEN_INTEL_MID)+= intel-mid-touch.o
 obj-$(CONFIG_TOUCHSCREEN_LPC32XX)  += lpc32xx_ts.o
 obj-$(CONFIG_TOUCHSCREEN_MAX11801) += max11801_ts.o
+obj-$(CONFIG_TOUCHSCREEN_MX25) += fsl-imx25-tcq.o
 obj-$(CONFIG_TOUCHSCREEN_MC13783)  += mc13783_ts.o
 obj-$(CONFIG_TOUCHSCREEN_MCS5000)  += mcs5000_ts.o
 obj-$(CONFIG_TOUCHSCREEN_MIGOR)+= migor_ts.o
diff --git a/drivers/input/touchscreen/fsl-imx25-tcq.c 
b/drivers/input/touchscreen/fsl-imx25-tcq.c
new file mode 100644
index ..2eb3bd00d56c
--- /dev/null
+++ b/drivers/input/touchscreen/fsl-imx25-tcq.c
@@ -0,0 +1,587 @@
+/*
+ * Copyright 2014 Markus Pargmann, Pengutronix 
+ * Based on driver from 2011:
+ *   Juergen Beisert, Pengutronix 
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * This is the driver for the imx25 TCQ (Touchscreen Conversion Queue)
+ * connected to the imx25 ADC.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static const char mx25_tcq_name[] = "mx25-tcq";
+
+enum mx25_tcq_mode {
+   MX25_TS_4WIRE,
+};
+
+struct mx25_tcq_priv {
+   struct regmap *regs;
+   struct regmap *core_regs;
+   struct input_dev *idev;
+   enum mx25_tcq_mode mode;
+   unsigned int pen_threshold;
+   unsigned int sample_count;
+   unsigned int expected_samples;
+   unsigned int pen_debounce;
+   unsigned int settling_time;
+   struct clk *clk;
+   int irq;
+};
+
+static struct regmap_config mx25_tcq_regconfig = {
+   .fast_io = true,
+   .max_register = 0x5c,
+   .reg_bits = 32,
+   .val_bits = 32,
+   .reg_stride = 4,
+};
+
+static struct of_device_id mx25_tcq_ids[] = {
+   { .compatible = "fsl,imx25-tcq", },
+   { /* Sentinel */ }
+};
+
+#define TSC_4WIRE_PRE_INDEX 0
+#define TSC_4WIRE_X_INDEX 1
+#define TSC_4WIRE_Y_INDEX 2
+#define TSC_4WIRE_POST_INDEX 3
+#define TSC_4WIRE_LEAVE 4
+
+#define MX25_TSC_DEF_THRESHOLD 80
+#define TSC_MAX_SAMPLES 16
+
+#define MX25_TSC_REPEAT_WAIT 14
+
+enum mx25_adc_configurations {
+   MX25_CFG_PRECHARGE = 0,
+   MX25_CFG_TOUCH_DETECT,
+   MX25_CFG_X_MEASUREMENT,
+   MX25_CFG_Y_MEASUREMENT,
+};
+
+#define MX25_PRECHARGE_VALUE (\
+   MX25_ADCQ_CFG_YPLL_OFF | \
+   MX25_ADCQ_CFG_XNUR_OFF | \
+   MX25_ADCQ_CFG_XPUL_HIGH | \
+   MX25_ADCQ_CFG_REFP_INT | \
+   MX25_ADCQ_CFG_IN_XP | \
+   MX25_ADCQ_CFG_REFN_NGND2 | \
+   MX25_ADCQ_CFG_IGS)
+
+#define MX25_TOUCH_DETECT_VALUE (\
+   MX25_ADCQ_CFG_YNLR | \
+   MX25_ADCQ_CFG_YPLL_OFF | \
+   MX25_ADCQ_CFG_XNUR_OFF | \
+   MX25_ADCQ_CFG_XPUL_OFF | \
+   MX25_ADCQ_CFG_REFP_IN