Re: [PATCH v2] iio: exynos-adc: add experimental touchscreen support

2014-07-27 Thread Heiko Stübner
Am Sonntag, 27. Juli 2014, 23:10:21 schrieb Hartmut Knaack:
 Arnd Bergmann schrieb:
  @@ -205,6 +217,9 @@ static void exynos_adc_v1_init_hw(struct exynos_adc
  *info) 
  /* Enable 12-bit ADC resolution */
  con1 |= ADC_V1_CON_RES;
  writel(con1, ADC_V1_CON(info-regs));
  
  +
  +   /* set default touchscreen delay */
 
 Any information about how many µs/ms it is actually set with this value?

ADC conversion is delayed by counting this value. Counting clock is pclk.
So, I guess here 1 pclk ticks.


Heiko

 
  +   writel(1, ADC_V1_DLY(info-regs));
  
   }
   

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


[PATCH v2] iio: exynos-adc: add experimental touchscreen support

2014-07-22 Thread Arnd Bergmann
This adds support for the touchscreen on Samsung s3c64xx.
The driver is completely untested but shows roughly how
it could be done, following the example of the at91 driver.

Open questions include:

- compared to the old plat-samsung/adc driver, there is
  no support for prioritizing ts over other clients, nor
  for oversampling. From my reading of the code, the
  priorities didn't actually have any effect at all, but
  the oversampling might be needed. Maybe the original
  authors have some insight.

- We probably need to add support for platform_data as well,
  I've skipped this so far.

Signed-off-by: Arnd Bergmann a...@arndb.de
---
This should address all previous comments, and I've also added
a write to ADC_V1_DLY() as the old driver does.

diff --git a/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt 
b/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt
index cad81b666a67..ba30836c73cb 100644
--- a/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt
+++ b/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt
@@ -43,6 +43,10 @@ Required properties:
   and compatible ADC block)
 - vdd-supply   VDD input supply.
 
+Optional properties:
+- has-touchscreen: If present, indicates that a touchscreen is
+   connected an usable.
+
 Note: child nodes can be added for auto probing from device tree.
 
 Example: adding device info in dtsi file
diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index 420c5cda09c3..3b684a117b9c 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -34,6 +34,7 @@
 #include linux/regulator/consumer.h
 #include linux/of_platform.h
 #include linux/err.h
+#include linux/input.h
 
 #include linux/iio/iio.h
 #include linux/iio/machine.h
@@ -66,6 +67,9 @@
 
 #define ADC_S3C2410_CON_SELMUX(x) (((x)0x7)3)
 
+/* touch screen always uses channel 0 */
+#define ADC_S3C2410_MUX_TS 0
+
 /* ADCTSC Register Bits */
 #define ADC_S3C2443_TSC_UD_SEN (1u  8)
 #define ADC_S3C2410_TSC_YM_SEN (1u  7)
@@ -103,24 +107,32 @@
 
 /* Bit definitions common for ADC_V1 and ADC_V2 */
 #define ADC_CON_EN_START   (1u  0)
+#define ADC_DATX_PRESSED   (1u  15)
 #define ADC_DATX_MASK  0xFFF
+#define ADC_DATY_MASK  0xFFF
 
 #define EXYNOS_ADC_TIMEOUT (msecs_to_jiffies(100))
 
 struct exynos_adc {
struct exynos_adc_data  *data;
struct device   *dev;
+   struct input_dev*input;
void __iomem*regs;
void __iomem*enable_reg;
struct clk  *clk;
struct clk  *sclk;
unsigned intirq;
+   unsigned inttsirq;
struct regulator*vdd;
 
struct completion   completion;
 
u32 value;
unsigned intversion;
+
+   boolread_ts;
+   u32 ts_x;
+   u32 ts_y;
 };
 
 struct exynos_adc_data {
@@ -205,6 +217,9 @@ static void exynos_adc_v1_init_hw(struct exynos_adc *info)
/* Enable 12-bit ADC resolution */
con1 |= ADC_V1_CON_RES;
writel(con1, ADC_V1_CON(info-regs));
+
+   /* set default touchscreen delay */
+   writel(1, ADC_V1_DLY(info-regs));
 }
 
 static void exynos_adc_v1_exit_hw(struct exynos_adc *info)
@@ -390,12 +405,54 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
return ret;
 }
 
+static int exynos_read_s3c64xx_ts(struct iio_dev *indio_dev, int *x, int *y)
+{
+   struct exynos_adc *info = iio_priv(indio_dev);
+   unsigned long timeout;
+   int ret;
+
+   mutex_lock(indio_dev-mlock);
+   info-read_ts = true;
+
+   reinit_completion(info-completion);
+
+   writel(ADC_S3C2410_TSC_PULL_UP_DISABLE | ADC_TSC_AUTOPST,
+  ADC_V1_TSC(info-regs));
+
+   /* Select the ts channel to be used and Trigger conversion */
+   info-data-start_conv(info, ADC_S3C2410_MUX_TS);
+
+   timeout = wait_for_completion_timeout
+   (info-completion, EXYNOS_ADC_TIMEOUT);
+   if (timeout == 0) {
+   dev_warn(indio_dev-dev, Conversion timed out! Resetting\n);
+   if (info-data-init_hw)
+   info-data-init_hw(info);
+   ret = -ETIMEDOUT;
+   } else {
+   *x = info-ts_x;
+   *y = info-ts_y;
+   ret = 0;
+   }
+
+   info-read_ts = false;
+   mutex_unlock(indio_dev-mlock);
+
+   return ret;
+}
+
 static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
 {
struct exynos_adc *info = (struct exynos_adc *)dev_id;
 
/* Read value */
-   info-value = readl(ADC_V1_DATX(info-regs))  ADC_DATX_MASK;
+   if (info-read_ts) {
+   info-ts_x = readl(ADC_V1_DATX(info-regs));
+   info-ts_y = readl(ADC_V1_DATY(info-regs));

Re: [PATCH v2] iio: exynos-adc: add experimental touchscreen support

2014-07-22 Thread Varka Bhadram


On Tuesday 22 July 2014 06:33 PM, Arnd Bergmann wrote:

(...)

  
+static int exynos_read_s3c64xx_ts(struct iio_dev *indio_dev, int *x, int *y)

+{
+   struct exynos_adc *info = iio_priv(indio_dev);
+   unsigned long timeout;
+   int ret;
+
+   mutex_lock(indio_dev-mlock);
+   info-read_ts = true;
+
+   reinit_completion(info-completion);
+
+   writel(ADC_S3C2410_TSC_PULL_UP_DISABLE | ADC_TSC_AUTOPST,
+  ADC_V1_TSC(info-regs));
+
+   /* Select the ts channel to be used and Trigger conversion */
+   info-data-start_conv(info, ADC_S3C2410_MUX_TS);
+
+   timeout = wait_for_completion_timeout
+   (info-completion, EXYNOS_ADC_TIMEOUT);


Should be properly aligned:

wait_for_completion_timeout(info-completion,
EXYNOS_ADC_TIMEOUT);

--
Regards,
Varka Bhadram

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


Re: [PATCH v2] iio: exynos-adc: add experimental touchscreen support

2014-07-22 Thread Dmitry Torokhov
On Tue, Jul 22, 2014 at 03:03:12PM +0200, Arnd Bergmann wrote:
 This adds support for the touchscreen on Samsung s3c64xx.
 The driver is completely untested but shows roughly how
 it could be done, following the example of the at91 driver.
 
 Open questions include:
 
 - compared to the old plat-samsung/adc driver, there is
   no support for prioritizing ts over other clients, nor
   for oversampling. From my reading of the code, the
   priorities didn't actually have any effect at all, but
   the oversampling might be needed. Maybe the original
   authors have some insight.
 
 - We probably need to add support for platform_data as well,
   I've skipped this so far.
 
 Signed-off-by: Arnd Bergmann a...@arndb.de
 ---
 This should address all previous comments, and I've also added
 a write to ADC_V1_DLY() as the old driver does.
 
 diff --git a/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt 
 b/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt
 index cad81b666a67..ba30836c73cb 100644
 --- a/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt
 +++ b/Documentation/devicetree/bindings/arm/samsung/exynos-adc.txt
 @@ -43,6 +43,10 @@ Required properties:
  and compatible ADC block)
  - vdd-supply VDD input supply.
  
 +Optional properties:
 +- has-touchscreen:   If present, indicates that a touchscreen is
 + connected an usable.
 +
  Note: child nodes can be added for auto probing from device tree.
  
  Example: adding device info in dtsi file
 diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
 index 420c5cda09c3..3b684a117b9c 100644
 --- a/drivers/iio/adc/exynos_adc.c
 +++ b/drivers/iio/adc/exynos_adc.c
 @@ -34,6 +34,7 @@
  #include linux/regulator/consumer.h
  #include linux/of_platform.h
  #include linux/err.h
 +#include linux/input.h
  
  #include linux/iio/iio.h
  #include linux/iio/machine.h
 @@ -66,6 +67,9 @@
  
  #define ADC_S3C2410_CON_SELMUX(x) (((x)0x7)3)
  
 +/* touch screen always uses channel 0 */
 +#define ADC_S3C2410_MUX_TS   0
 +
  /* ADCTSC Register Bits */
  #define ADC_S3C2443_TSC_UD_SEN   (1u  8)
  #define ADC_S3C2410_TSC_YM_SEN   (1u  7)
 @@ -103,24 +107,32 @@
  
  /* Bit definitions common for ADC_V1 and ADC_V2 */
  #define ADC_CON_EN_START (1u  0)
 +#define ADC_DATX_PRESSED (1u  15)
  #define ADC_DATX_MASK0xFFF
 +#define ADC_DATY_MASK0xFFF
  
  #define EXYNOS_ADC_TIMEOUT   (msecs_to_jiffies(100))
  
  struct exynos_adc {
   struct exynos_adc_data  *data;
   struct device   *dev;
 + struct input_dev*input;
   void __iomem*regs;
   void __iomem*enable_reg;
   struct clk  *clk;
   struct clk  *sclk;
   unsigned intirq;
 + unsigned inttsirq;
   struct regulator*vdd;
  
   struct completion   completion;
  
   u32 value;
   unsigned intversion;
 +
 + boolread_ts;
 + u32 ts_x;
 + u32 ts_y;
  };
  
  struct exynos_adc_data {
 @@ -205,6 +217,9 @@ static void exynos_adc_v1_init_hw(struct exynos_adc *info)
   /* Enable 12-bit ADC resolution */
   con1 |= ADC_V1_CON_RES;
   writel(con1, ADC_V1_CON(info-regs));
 +
 + /* set default touchscreen delay */
 + writel(1, ADC_V1_DLY(info-regs));
  }
  
  static void exynos_adc_v1_exit_hw(struct exynos_adc *info)
 @@ -390,12 +405,54 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
   return ret;
  }
  
 +static int exynos_read_s3c64xx_ts(struct iio_dev *indio_dev, int *x, int *y)
 +{
 + struct exynos_adc *info = iio_priv(indio_dev);
 + unsigned long timeout;
 + int ret;
 +
 + mutex_lock(indio_dev-mlock);
 + info-read_ts = true;
 +
 + reinit_completion(info-completion);
 +
 + writel(ADC_S3C2410_TSC_PULL_UP_DISABLE | ADC_TSC_AUTOPST,
 +ADC_V1_TSC(info-regs));
 +
 + /* Select the ts channel to be used and Trigger conversion */
 + info-data-start_conv(info, ADC_S3C2410_MUX_TS);
 +
 + timeout = wait_for_completion_timeout
 + (info-completion, EXYNOS_ADC_TIMEOUT);
 + if (timeout == 0) {
 + dev_warn(indio_dev-dev, Conversion timed out! Resetting\n);
 + if (info-data-init_hw)
 + info-data-init_hw(info);
 + ret = -ETIMEDOUT;
 + } else {
 + *x = info-ts_x;
 + *y = info-ts_y;
 + ret = 0;
 + }
 +
 + info-read_ts = false;
 + mutex_unlock(indio_dev-mlock);
 +
 + return ret;
 +}
 +
  static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
  {
   struct exynos_adc *info = (struct exynos_adc *)dev_id;
  
   /* Read value */
 - info-value = readl(ADC_V1_DATX(info-regs))  ADC_DATX_MASK;
 + if (info-read_ts) {

Re: [PATCH v2] iio: exynos-adc: add experimental touchscreen support

2014-07-22 Thread Arnd Bergmann
On Tuesday 22 July 2014 11:09:04 Dmitry Torokhov wrote:
  @@ -565,6 +722,15 @@ static int exynos_adc_probe(struct platform_device 
  *pdev)
if (info-data-init_hw)
info-data-init_hw(info);
   
  + /* leave out any TS related code if unreachable */
  + if (IS_BUILTIN(CONFIG_INPUT) ||
  + (IS_MODULE(CONFIG_INPUT)  config_enabled(MODULE)))
 
 This is ugly... We need IS_SUBSYSTEM_AVAILABLE() wrapper for this...
 
 Anyway,
 
 Acked-by: Dmitry Torokhov dmitry.torok...@gmail.com
 
 

I actually have a patch to introduce IS_REACHABLE() for this purpose,
but I haven't sent it out for review yet. The main user of this would
be drivers/media, which had the correct logic earlier until someone
tried to simplify it by replacing it all with IS_ENABLED()...

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