Skip to contentSkip to conversation

input: Add CSR SiRFSoC internal touchscreen driver

PATCH Superseded Barry Song 5 participants 8 messages Jun 23, 2014 – Jun 24, 2014

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Barry Song

author
#0 lore raw

cover input: Add CSR SiRFSoC internal touchscreen driver

From: Barry Song <[email protected]>

patch "lib: int_sqrt: add int64_sqrt routine" add a int64_sqrt() API which CSR SiRFSoC internal touchscreen driver needs. and patch "input:
sirfsoc_rs - add sirfsoc internal ADC-based touchscreen driver" adds the new driver.

Guoying Zhang (1):
input: sirfsoc_rs - add sirfsoc internal ADC-based touchscreen driver

Yibo Cai (1):
lib: int_sqrt: add int64_sqrt routine

 drivers/input/touchscreen/Kconfig      |  10 +
 drivers/input/touchscreen/Makefile     |   1 +
 drivers/input/touchscreen/sirfsoc_ts.c | 658 +++++++++++++++++++++++++++++++++
 include/linux/kernel.h                 |   1 +
 lib/int_sqrt.c                         |  27 ++
 5 files changed, 697 insertions(+)
 create mode 100644 drivers/input/touchscreen/sirfsoc_ts.c
Signature · 1 line
1.9.3
author
#1 lore raw

PATCH 1/2 lib: int_sqrt: add int64_sqrt routine

From: Yibo Cai <[email protected]>

Get square root of a 64-bit digit on 32bit platforms. CSR SiRFSoC touchscreen driver needs it.

---
 include/linux/kernel.h |  1 +
 lib/int_sqrt.c         | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)
include/linux/kernel.h +1 -0
index 4c52907..6e63081 100644
@@ -418,6 +418,7 @@ struct pid;
 extern struct pid *session_of_pgrp(struct pid *pgrp);
 
 unsigned long int_sqrt(unsigned long);
+unsigned long long int64_sqrt(unsigned long long);
 
 extern void bust_spinlocks(int yes);
 extern int oops_in_progress;		/* If set, an oops, panic(), BUG() or die() is in progress */
lib/int_sqrt.c +27 -0
index 1ef4cc3..2aa9fcc 100644
@@ -36,3 +36,30 @@ unsigned long int_sqrt(unsigned long x)
 	return y;
 }
 EXPORT_SYMBOL(int_sqrt);
+
+/*
+ * Square root of a 64-bit digit.
+ * Same as int_sqrt on 64-bit platforms where "long" equals "long long"
+ */
+unsigned long long int64_sqrt(unsigned long long x)
+{
+	unsigned long long m = 0, y = 0, b = 0;
+
+	if (x <= 1)
+		return x;
+
+	m = 1ULL << (BITS_PER_LONG_LONG - 2);
+	while (m != 0) {
+		b = y + m;
+		y >>= 1;
+
+		if (x >= b) {
+			x -= b;
+			y += m;
+		}
+		m >>= 2;
+	}
+
+	return y;
+}
+EXPORT_SYMBOL(int64_sqrt);
Signature · 1 line
1.9.3
#2 lore raw

Re: [PATCH 1/2] lib: int_sqrt: add int64_sqrt routine

Quoted 2 lines

Get square root of a 64-bit digit on 32bit platforms. CSR SiRFSoC touchscreen driver needs it.

maybe the code could be #MACRO()'d to avoid duplication

see comment below

Quoted 18 lines
include/linux/kernel.h +1 -0
index 4c52907..6e63081 100644
@@ -418,6 +418,7 @@ struct pid;
 extern struct pid *session_of_pgrp(struct pid *pgrp);
 
 unsigned long int_sqrt(unsigned long);
+unsigned long long int64_sqrt(unsigned long long);
 
 extern void bust_spinlocks(int yes);
 extern int oops_in_progress;		/* If set, an oops, panic(), BUG() or die() is in progress */
lib/int_sqrt.c +0 -0
index 1ef4cc3..2aa9fcc 100644
@@ -36,3 +36,30 @@ unsigned long int_sqrt(unsigned long x)
 	return y;

lib/int_sqrt.c unsigned long int_sqrt(unsigned long x) · line 46

Quoted 10 lines
lib/int_sqrt.c +8 -0
 }
 EXPORT_SYMBOL(int_sqrt);
+
+/*
+ * Square root of a 64-bit digit.
+ * Same as int_sqrt on 64-bit platforms where "long" equals "long long"
+ */
+unsigned long long int64_sqrt(unsigned long long x)
+{
+	unsigned long long m = 0, y = 0, b = 0;

initialization for b, m not needed

the original int_sqrt() code correctly skips initialization

Quoted 20 lines
lib/int_sqrt.c +19 -0
+
+	if (x <= 1)
+		return x;
+
+	m = 1ULL << (BITS_PER_LONG_LONG - 2);
+	while (m != 0) {
+		b = y + m;
+		y >>= 1;
+
+		if (x >= b) {
+			x -= b;
+			y += m;
+		}
+		m >>= 2;
+	}
+
+	return y;
+}
+EXPORT_SYMBOL(int64_sqrt);
Signature · 2 lines
Peter Meerwald
+43-664-2444418 (mobile)
#3 lore raw

RE: [PATCH 1/2] lib: int_sqrt: add int64_sqrt routine

Hello Peter,

Quoted 4 lines
Quoted 2 lines

Get square root of a 64-bit digit on 32bit platforms. CSR SiRFSoC touchscreen driver needs it.

maybe the code could be #MACRO()'d to avoid duplication

Do you mean to define int64_sqrt() directly as int_sqrt() on a 64 bit platform where sizeof(long) == sizeof(long long)?

Yibo
________________________________________
From: Peter Meerwald [[email protected]]
Sent: Monday, June 23, 2014 5:52 PM
To: Barry Song
Cc: [email protected]; [email protected]; [email protected]; [email protected]; DL-SHA-WorkGroupLinux; Yibo Cai; Barry Song
Subject: Re: [PATCH 1/2] lib: int_sqrt: add int64_sqrt routine

Quoted 2 lines

Get square root of a 64-bit digit on 32bit platforms. CSR SiRFSoC touchscreen driver needs it.

maybe the code could be #MACRO()'d to avoid duplication

see comment below

Quoted 18 lines
include/linux/kernel.h +1 -0
index 4c52907..6e63081 100644
@@ -418,6 +418,7 @@ struct pid;
 extern struct pid *session_of_pgrp(struct pid *pgrp);
 
 unsigned long int_sqrt(unsigned long);
+unsigned long long int64_sqrt(unsigned long long);
 
 extern void bust_spinlocks(int yes);
 extern int oops_in_progress;         /* If set, an oops, panic(), BUG() or die() is in progress */
lib/int_sqrt.c +0 -0
index 1ef4cc3..2aa9fcc 100644
@@ -36,3 +36,30 @@ unsigned long int_sqrt(unsigned long x)
      return y;

lib/int_sqrt.c unsigned long int_sqrt(unsigned long x) · line 46

Quoted 10 lines
lib/int_sqrt.c +8 -0
 }
 EXPORT_SYMBOL(int_sqrt);
+
+/*
+ * Square root of a 64-bit digit.
+ * Same as int_sqrt on 64-bit platforms where "long" equals "long long"
+ */
+unsigned long long int64_sqrt(unsigned long long x)
+{
+     unsigned long long m = 0, y = 0, b = 0;

initialization for b, m not needed

the original int_sqrt() code correctly skips initialization

Quoted 10 lines
lib/int_sqrt.c +9 -0
+
+     if (x <= 1)
+             return x;
+
+     m = 1ULL << (BITS_PER_LONG_LONG - 2);
+     while (m != 0) {
+             b = y + m;
+             y >>= 1;
+

lib/int_sqrt.c unsigned long int_sqrt(unsigned long x) · line 65

Quoted 10 lines
lib/int_sqrt.c +10 -0
+             if (x >= b) {
+                     x -= b;
+                     y += m;
+             }
+             m >>= 2;
+     }
+
+     return y;
+}
+EXPORT_SYMBOL(int64_sqrt);

--

Peter Meerwald
+43-664-2444418 (mobile)

To report this email as spam click https://www.mailcontrol.com/sr/MZbqvYs5QwJvpeaetUwhCQ== .

Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Keep up to date with CSR on our technical blog, www.csr.com/blog, CSR people blog, www.csr.com/people, YouTube, www.youtube.com/user/CSRplc, Facebook, www.facebook.com/pages/CSR/191038434253534, or follow us on Twitter at www.twitter.com/CSR_plc. New for 2014, you can now access the wide range of products powered by aptX at www.aptx.com.

#4 lore raw

RE: [PATCH 1/2] lib: int_sqrt: add int64_sqrt routine

Hello,

Quoted 4 lines
Quoted 1 line

maybe the code could be #MACRO()'d to avoid duplication

Do you mean to define int64_sqrt() directly as int_sqrt() on a 64 bit platform where sizeof(long) == sizeof(long long)?

something along the lines of

#define INT_SQRT(name, type) \

   type name(type x) \ 
      type m, y = 0, b; \

...

INT_SQRT(int_sqrt, unsigned long);
INT_SQRT(int64_sqrt, unsigned long long);

not sure if it is worth it

regards, p.

Quoted 81 lines

________________________________________
From: Peter Meerwald [[email protected]]
Sent: Monday, June 23, 2014 5:52 PM
To: Barry Song
Cc: [email protected]; [email protected]; [email protected]; [email protected]; DL-SHA-WorkGroupLinux; Yibo Cai; Barry Song
Subject: Re: [PATCH 1/2] lib: int_sqrt: add int64_sqrt routine

Quoted 2 lines

Get square root of a 64-bit digit on 32bit platforms. CSR SiRFSoC touchscreen driver needs it.

maybe the code could be #MACRO()'d to avoid duplication

see comment below

Quoted 18 lines
include/linux/kernel.h +1 -0
index 4c52907..6e63081 100644
@@ -418,6 +418,7 @@ struct pid;
 extern struct pid *session_of_pgrp(struct pid *pgrp);
 
 unsigned long int_sqrt(unsigned long);
+unsigned long long int64_sqrt(unsigned long long);
 
 extern void bust_spinlocks(int yes);
 extern int oops_in_progress;         /* If set, an oops, panic(), BUG() or die() is in progress */
lib/int_sqrt.c +0 -0
index 1ef4cc3..2aa9fcc 100644
@@ -36,3 +36,30 @@ unsigned long int_sqrt(unsigned long x)
      return y;

lib/int_sqrt.c unsigned long int_sqrt(unsigned long x) · line 46

Quoted 10 lines
lib/int_sqrt.c +8 -0
 }
 EXPORT_SYMBOL(int_sqrt);
+
+/*
+ * Square root of a 64-bit digit.
+ * Same as int_sqrt on 64-bit platforms where "long" equals "long long"
+ */
+unsigned long long int64_sqrt(unsigned long long x)
+{
+     unsigned long long m = 0, y = 0, b = 0;

initialization for b, m not needed

the original int_sqrt() code correctly skips initialization

Quoted 10 lines
lib/int_sqrt.c +9 -0
+
+     if (x <= 1)
+             return x;
+
+     m = 1ULL << (BITS_PER_LONG_LONG - 2);
+     while (m != 0) {
+             b = y + m;
+             y >>= 1;
+

lib/int_sqrt.c unsigned long int_sqrt(unsigned long x) · line 65

Quoted 10 lines
lib/int_sqrt.c +10 -0
+             if (x >= b) {
+                     x -= b;
+                     y += m;
+             }
+             m >>= 2;
+     }
+
+     return y;
+}
+EXPORT_SYMBOL(int64_sqrt);

--

Peter Meerwald
+43-664-2444418 (mobile)

To report this email as spam click https://www.mailcontrol.com/sr/MZbqvYs5QwJvpeaetUwhCQ== .

Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Keep up to date with CSR on our technical blog, www.csr.com/blog, CSR people blog, www.csr.com/people, YouTube, www.youtube.com/user/CSRplc, Facebook, www.facebook.com/pages/CSR/191038434253534, or follow us on Twitter at www.twitter.com/CSR_plc. New for 2014, you can now access the wide range of products powered by aptX at www.aptx.com.

Signature · 2 lines
Peter Meerwald
+43-664-2444418 (mobile)
maintainer
#5 lore raw

Re: [PATCH 1/2] lib: int_sqrt: add int64_sqrt routine

Quoted 10 lines · On Tue, 24 Jun 2014 08:15:55 +0200 (CEST) Peter Meerwald <[email protected]>…
Quoted 4 lines
Quoted 1 line

maybe the code could be #MACRO()'d to avoid duplication

Do you mean to define int64_sqrt() directly as int_sqrt() on a 64 bit platform where sizeof(long) == sizeof(long long)?

something along the lines of

#define INT_SQRT(name, type) \
   type name(type x) \ 
      type m, y = 0, b; \
Quoted 6 lines

...

INT_SQRT(int_sqrt, unsigned long);
INT_SQRT(int64_sqrt, unsigned long long);

not sure if it is worth it

We have made smaller optimisations in the past ;)

But not a macro, please:

#ifdef CONFIG_64BIT
static inline unsigned long long int64_sqrt(unsigned long long x)

{
	return int_sqrt(x);
}

#else
unsigned long long int64_sqrt(unsigned long long x); #endif

#6 lore raw

Re: [PATCH 1/2] lib: int_sqrt: add int64_sqrt routine

In reply to Barry Song
Quoted 50 lines · Barry Song

From: Yibo Cai <[email protected]>

Get square root of a 64-bit digit on 32bit platforms. CSR SiRFSoC touchscreen driver needs it.

---
 include/linux/kernel.h |  1 +
 lib/int_sqrt.c         | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)
include/linux/kernel.h +1 -0
index 4c52907..6e63081 100644
@@ -418,6 +418,7 @@ struct pid;
 extern struct pid *session_of_pgrp(struct pid *pgrp);
 
 unsigned long int_sqrt(unsigned long);
+unsigned long long int64_sqrt(unsigned long long);
 
 extern void bust_spinlocks(int yes);
 extern int oops_in_progress;           /* If set, an oops, panic(), BUG() or die() is in progress */
lib/int_sqrt.c +17 -0
index 1ef4cc3..2aa9fcc 100644
@@ -36,3 +36,30 @@ unsigned long int_sqrt(unsigned long x)
        return y;
 }
 EXPORT_SYMBOL(int_sqrt);
+
+/*
+ * Square root of a 64-bit digit.
+ * Same as int_sqrt on 64-bit platforms where "long" equals "long long"
+ */
+unsigned long long int64_sqrt(unsigned long long x)
+{
+       unsigned long long m = 0, y = 0, b = 0;
+
+       if (x <= 1)
+               return x;
+
+       m = 1ULL << (BITS_PER_LONG_LONG - 2);
+       while (m != 0) {
+               b = y + m;
+               y >>= 1;
+

lib/int_sqrt.c unsigned long int_sqrt(unsigned long x) · line 65

Quoted 10 lines
lib/int_sqrt.c +10 -0
+               if (x >= b) {
+                       x -= b;
+                       y += m;
+               }
+               m >>= 2;
+       }
+
+       return y;
+}
+EXPORT_SYMBOL(int64_sqrt);

Maybe it's a stupid question (I'm new to kernel programming), but why don't you use a for-loop instead of a while-loop? (apart from following the already-existing code of int_sqrt.c)

E.g.:

    for (m = 1ULL << (BITS_PER_LONG_LONG - 2); m != 0; m >>= 2) {
        b = y + m;
        y >>= 1;

        if (x >= b) {
            x -= b;
            y += m;
        }
    }

Instead of:

    m = 1ULL << (BITS_PER_LONG_LONG - 2);
    while (m != 0) {
        b = y + m;
        y >>= 1;

        if (x >= b) {
            x -= b;
            y += m;
        }
        m >>= 2;
    }

Thanks,
Elias

author
#7 lore raw

PATCH 2/2 input: sirfsoc_rs - add sirfsoc internal ADC-based touchscreen driver

In reply to Barry Song

From: Guoying Zhang <[email protected]>

The Touch Screen (TS) Controller is used for driving the touch screen to perform coordinates and pressure measurements. It supports a 4-wire resistive touch screen interface.

in this driver, we support both single and dual touch. The dual touch is actually based on a software algorithm.

The idea is to recover original dual touch coordinates from AD samples.

- Equivalent schematic.
touch1 touch2
| |
v v
RX1 A RX2 D RX3
Upper Plane: XP ----/\/\/\----o----/\/\/\----o----/\/\/\---- XN

                               |              |
                               /              /
                       Rtouch1 \      Rtouch2 \
                               /              /
                               \              \
                               |              |
Lower Plane:  YP ----/\/\/\----o----/\/\/\----o----/\/\/\---- YN
                       RY1     B      RY2     C      RY3

Touch points(touch1/2) introduce two resisters(Rtouch1/2) between upper plane and lower plane, as well as cutting each plane into three consecutive resisters(RX1/2/3, RY1/2/3).

- Eight AD samples can be got from sirf touchscreen controller, which serve as known conditions to solve the above resister network.
---------------------------------
| Power | AD samples |
---------------------------------
| Vcc | GND | Sample1 | Sample2 |
---------------------------------

  | XP  | XN  |   YP    |   YN    | \
  ---------------------------------  > Recover coordinates
  | YP  | YN  |   XP    |   XN    | /
  ---------------------------------
  | XP  | YN  |   YP    |   XN    | \
  ---------------------------------  > Calculate Rtouch
  | YP  | XN  |   XP    |   YN    | /

---------------------------------

- Non-trivial calculation is required to recover dual touch coordinates as we need to resolve some second order equations and deal with very big or small float numbers. Some tricks are necessary to make it work.
* float numbers are represented by enlarged integers.

    ex. (float)1.03 -> *1024 -> (u32)1054

* Sequence of multiply and division is important as it may result in overflow or underflow if switched, though in theory it's nonsense.
* Single touch dominates dual touch. Single touch detection must be kept fast and accurate.

---
 drivers/input/touchscreen/Kconfig      |  10 +
 drivers/input/touchscreen/Makefile     |   1 +
 drivers/input/touchscreen/sirfsoc_ts.c | 658 +++++++++++++++++++++++++++++++++
 3 files changed, 669 insertions(+)
 create mode 100644 drivers/input/touchscreen/sirfsoc_ts.c
drivers/input/touchscreen/Kconfig +10 -0
index a23a94b..8312b7c 100644
@@ -868,6 +868,16 @@ config TOUCHSCREEN_PCAP
 	  To compile this driver as a module, choose M here: the
 	  module will be called pcap_ts.
 
+config TOUCHSCREEN_SIRFSOC
+	tristate "SiRFSoC touchscreen"
+	depends on ARCH_SIRF
+	select IIO
+	help
+	  Say Y here if you have a SiRFSoC internal ADC based touchscreen.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called sirfsoc_ts.
+
 config TOUCHSCREEN_ST1232
 	tristate "Sitronix ST1232 touchscreen controllers"
 	depends on I2C
drivers/input/touchscreen/Makefile +1 -0
index 126479d..ef438f7 100644
@@ -52,6 +52,7 @@ obj-$(CONFIG_TOUCHSCREEN_PCAP)		+= pcap_ts.o
 obj-$(CONFIG_TOUCHSCREEN_PENMOUNT)	+= penmount.o
 obj-$(CONFIG_TOUCHSCREEN_PIXCIR)	+= pixcir_i2c_ts.o
 obj-$(CONFIG_TOUCHSCREEN_S3C2410)	+= s3c2410_ts.o
+obj-$(CONFIG_TOUCHSCREEN_SIRFSOC)       += sirfsoc_ts.o
 obj-$(CONFIG_TOUCHSCREEN_ST1232)	+= st1232.o
 obj-$(CONFIG_TOUCHSCREEN_STMPE)		+= stmpe-ts.o
 obj-$(CONFIG_TOUCHSCREEN_SUN4I)		+= sun4i-ts.o
drivers/input/touchscreen/sirfsoc_ts.c new file +658 -0

658 lines not on this page · raw message

Signature · 1 line
1.9.3