Input: Cypress TTSP device driver
Subsystems (2)
Cypress TrueTouch(tm) Standard Product controllers are found in a wide range of embedded devices. This patchset adds support for a variety of TTSP controllers.
The original author of the driver is Kevin McNeely <[email protected]>
Since the hardware is capable of tracking identifiable contacts and the original driver used multi-touch protocol type A (stateless), I've added multi-touch protocol type B (stateful) support.
The driver is composed of a core driver that process the data sent by the contacts (fingers) and two bus specific interface modules (I2C and SPI).
The patchset is composed of:
[PATCH 1/3] Input: cyttsp - Cypress TTSP capacitive multi-touch screen support [PATCH 2/3] Input: cyttsp - add support for Cypress TTSP touchscreen I2C bus interface [PATCH 3/3] Input: cyttsp - add support for Cypress TTSP touchscreen SPI bus interface
PATCH 1/3 Input: cyttsp - Cypress TTSP capacitive multi-touch screen support
Cypress TrueTouch(tm) Standard Product controllers are found in a wide range of embedded devices. This driver add support for a variety of TTSP controllers.
The driver is composed of a core driver that process the data sent by the contacts and a set of bus specific interface modules. This patch adds the base core TTSP driver.
The original author of the driver is Kevin McNeely <[email protected]>
Since the hardware is capable of tracking identifiable contacts and the original driver used multi-touch protocol type A (stateless), multi-touch protocol type B (stateful) support was added by Javier Martinez Canillas.
--- drivers/input/touchscreen/Kconfig | 2 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/cyttsp/Kconfig | 4 + drivers/input/touchscreen/cyttsp/Makefile | 1 + drivers/input/touchscreen/cyttsp/cyttsp_core.c | 874 ++++++++++++++++++++++++ drivers/input/touchscreen/cyttsp/cyttsp_core.h | 56 ++ include/linux/input/cyttsp.h | 68 ++ 7 files changed, 1006 insertions(+), 0 deletions(-) create mode 100644 drivers/input/touchscreen/cyttsp/Kconfig create mode 100644 drivers/input/touchscreen/cyttsp/Makefile create mode 100644 drivers/input/touchscreen/cyttsp/cyttsp_core.c create mode 100644 drivers/input/touchscreen/cyttsp/cyttsp_core.h create mode 100644 include/linux/input/cyttsp.h
drivers/input/touchscreen/Kconfig +2 -0
@@ -726,4 +726,6 @@ config TOUCHSCREEN_TPS6507X To compile this driver as a module, choose M here: the module will be called tps6507x_ts. +source "drivers/input/touchscreen/cyttsp/Kconfig" + endif
drivers/input/touchscreen/Makefile +1 -0
@@ -60,3 +60,4 @@ obj-$(CONFIG_TOUCHSCREEN_WM97XX_MAINSTONE) += mainstone-wm97xx.o obj-$(CONFIG_TOUCHSCREEN_WM97XX_ZYLONITE) += zylonite-wm97xx.o obj-$(CONFIG_TOUCHSCREEN_W90X900) += w90p910_ts.o obj-$(CONFIG_TOUCHSCREEN_TPS6507X) += tps6507x-ts.o +obj-$(CONFIG_TOUCHSCREEN_CYTTSP_CORE) += cyttsp/
drivers/input/touchscreen/cyttsp/Kconfig new file +4 -0
@@ -0,0 +1,4 @@ +config TOUCHSCREEN_CYTTSP_CORE + tristate "Cypress TTSP touchscreen core" + help + Always activated for Cypress TTSP touchscreen
drivers/input/touchscreen/cyttsp/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_TOUCHSCREEN_CYTTSP_CORE) += cyttsp_core.o
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +874 -0
874 lines not on this page · raw message
drivers/input/touchscreen/cyttsp/cyttsp_core.h new file +56 -0
56 lines not on this page · raw message
include/linux/input/cyttsp.h new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 2/3 Input: cyttsp - add support for Cypress TTSP touchscreen I2C bus interface
In reply to Javier Martinez CanillasThe driver is composed of a core driver that process the data sent by the contacts and a set of bus specific interface modules.
This patch add supports for the Cypress TTSP I2C bus interface.
The original author of the driver is Kevin McNeely <[email protected]>
--- drivers/input/touchscreen/cyttsp/Kconfig | 12 ++ drivers/input/touchscreen/cyttsp/Makefile | 1 + drivers/input/touchscreen/cyttsp/cyttsp_i2c.c | 188 +++++++++++++++++++++++++ 3 files changed, 201 insertions(+), 0 deletions(-) create mode 100644 drivers/input/touchscreen/cyttsp/cyttsp_i2c.c
drivers/input/touchscreen/cyttsp/Kconfig +12 -0
@@ -2,3 +2,15 @@ config TOUCHSCREEN_CYTTSP_CORE tristate "Cypress TTSP touchscreen core" help Always activated for Cypress TTSP touchscreen + +config TOUCHSCREEN_CYTTSP_I2C + tristate "Cypress TTSP i2c touchscreen" + depends on I2C && TOUCHSCREEN_CYTTSP_CORE + help + Say Y here if you have a Cypress TTSP touchscreen + connected to your system with an I2C interface. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called cyttsp-i2c.
drivers/input/touchscreen/cyttsp/Makefile +1 -0
@@ -1 +1,2 @@ obj-$(CONFIG_TOUCHSCREEN_CYTTSP_CORE) += cyttsp_core.o +obj-$(CONFIG_TOUCHSCREEN_CYTTSP_I2C) += cyttsp_i2c.o
drivers/input/touchscreen/cyttsp/cyttsp_i2c.c new file +188 -0
188 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 3/3 Input: cyttsp - add support for Cypress TTSP touchscreen SPI bus interface
In reply to Javier Martinez CanillasThe driver is composed of a core driver that process the data sent by the contacts and a set of bus specific interface modules.
This patch add supports for the Cypress TTSP SPI bus interface.
The original author of the driver is Kevin McNeely <[email protected]>
--- drivers/input/touchscreen/cyttsp/Kconfig | 12 + drivers/input/touchscreen/cyttsp/Makefile | 1 + drivers/input/touchscreen/cyttsp/cyttsp_spi.c | 318 +++++++++++++++++++++++++ 3 files changed, 331 insertions(+), 0 deletions(-) create mode 100644 drivers/input/touchscreen/cyttsp/cyttsp_spi.c
drivers/input/touchscreen/cyttsp/Kconfig +12 -0
@@ -14,3 +14,15 @@ config TOUCHSCREEN_CYTTSP_I2C To compile this driver as a module, choose M here: the module will be called cyttsp-i2c. + +config TOUCHSCREEN_CYTTSP_SPI + tristate "Cypress TTSP spi touchscreen" + depends on SPI_MASTER && TOUCHSCREEN_CYTTSP_CORE + help + Say Y here if you have a Cypress TTSP touchscreen + connected to your with an SPI interface. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called cyttsp-spi.
drivers/input/touchscreen/cyttsp/Makefile +1 -0
@@ -1,2 +1,3 @@ obj-$(CONFIG_TOUCHSCREEN_CYTTSP_CORE) += cyttsp_core.o obj-$(CONFIG_TOUCHSCREEN_CYTTSP_I2C) += cyttsp_i2c.o +obj-$(CONFIG_TOUCHSCREEN_CYTTSP_SPI) += cyttsp_spi.o
drivers/input/touchscreen/cyttsp/cyttsp_spi.c new file +318 -0
318 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Dmitry Torokhov
maintainerRe: [PATCH 3/3] Input: cyttsp - add support for Cypress TTSP touchscreen SPI bus interface
Hi Javier,
Quoted 20 lines · Javier Martinez Canillas
drivers/input/touchscreen/cyttsp/cyttsp_spi.c new file +20
-0+ +static int cyttsp_spi_xfer_ (u8 op,struct cyttsp_spi *ts, +u8 reg,u8 *buf,int length) +{ +struct spi_message msg; +struct spi_transfer xfer[2 ]; +u8 *wr_buf = ts->wr_buf; +u8 *rd_buf = ts->rd_buf; +int retval; + +if (length >CY_SPI_DATA_SIZE ) { +dev_dbg (ts->ops.dev,"%s: length %d is too big.\n" , + __func__, length); +return -EINVAL ; + } + +memset (wr_buf,0 ,CY_SPI_DATA_BUF_SIZE ); +memset (rd_buf,0 ,CY_SPI_DATA_BUF_SIZE ); + + wr_buf[0 ] =0x00 ;/* header byte 0 */
drivers/input/touchscreen/cyttsp/cyttsp_spi.c line 105
Quoted 10 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c new file +10
-0+ wr_buf[1 ] =0xFF ;/* header byte 1 */ + wr_buf[2 ] = reg;/* reg index */ + wr_buf[3 ] = op;/* r/~w */ +if (op ==CY_SPI_WR_OP ) +memcpy (wr_buf +CY_SPI_CMD_BYTES , buf, length); + +memset ((void *)xfer,0 ,sizeof (xfer)); +spi_message_init (&msg); + xfer[0 ].tx_buf = wr_buf; + xfer[0 ].rx_buf = rd_buf;
Since we are setting both TX and RX buffer here does this mean that the device will not work with controllers in half-duplex mode? What is the amount of data that will be placed in rd_buf?
Quoted 7 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c new file +7
-0+if (op ==CY_SPI_WR_OP ) { + xfer[0 ].len = length +CY_SPI_CMD_BYTES ; +spi_message_add_tail (&xfer[0 ], &msg); + }else if (op ==CY_SPI_RD_OP ) { + xfer[0 ].len =CY_SPI_CMD_BYTES ; +spi_message_add_tail (&xfer[0 ], &msg); +
drivers/input/touchscreen/cyttsp/cyttsp_spi.c line 122
Quoted 10 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c new file +10
-0+ xfer[1 ].rx_buf = buf; + xfer[1 ].len = length; +spi_message_add_tail (&xfer[1 ], &msg); + } + + retval =spi_sync_tmo (ts, &msg); +if (retval <0 ) { +dev_dbg (ts->ops.dev,"%s: spi sync error %d, len=%d, op=%d\n" , + __func__, retval, xfer[1 ].len, op); + retval =0 ;
Why do we ignore the error?
drivers/input/touchscreen/cyttsp/cyttsp_spi.c line 128
Quoted 6 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c new file +6
-0+ } + +if (op ==CY_SPI_RD_OP ) { +if ((rd_buf[CY_SPI_SYNC_BYTE ] ==CY_SPI_SYNC_ACK1 ) && + (rd_buf[CY_SPI_SYNC_BYTE +1 ] ==CY_SPI_SYNC_ACK2 )) + retval =0 ;
What about write operation? Does the device send anything in rd_buf for write command?
Quoted 19 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c new file +19
-0+else { +int i; +for (i =0 ; i < (CY_SPI_CMD_BYTES ); i++) +dev_dbg (ts->ops.dev, +"%s: test rd_buf[%d]:0x%02x\n" , + __func__, i, rd_buf[i]); +for (i =0 ; i < (length); i++) +dev_dbg (ts->ops.dev, +"%s: test buf[%d]:0x%02x\n" , + __func__, i, buf[i]); + retval =1 ; + } + } +return retval; +} + +static int cyttsp_spi_xfer (u8 op,struct cyttsp_spi *ts, +u8 reg,u8 *buf,int length) +{
drivers/input/touchscreen/cyttsp/cyttsp_spi.c line 157
Quoted 10 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c new file +10
-0+int tries; +int retval; + +if (op ==CY_SPI_RD_OP ) { +for (tries =CY_NUM_RETRY ; tries; tries--) { + retval =cyttsp_spi_xfer_ (op, ts, reg, buf, length); +if (retval ==0 ) +break ; +else +msleep (20 );
Why do we need retry in SPI case but do not need it when device is connected via I2C? And not on writes?
Quoted 33 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c new file +33
-0+ } + }else { + retval =cyttsp_spi_xfer_ (op, ts, reg, buf, length); + } + +return retval; +} + +static s32 ttsp_spi_read_block_data (void *handle,u8 addr, +u8 length,void *data) +{ + struct cyttsp_spi *ts = container_of(handle, struct cyttsp_spi, ops); +int retval; + + retval =cyttsp_spi_xfer (CY_SPI_RD_OP , ts, addr, data, length); +if (retval <0 ) +dev_dbg (ts->ops.dev,"%s: ttsp_spi_read_block_data failed\n" , + __func__); + +/* +* Do not print the above error if the data sync bytes were not found. +* This is a normal condition for the bootloader loader startup and need +* to retry until data sync bytes are found. +*/ +if (retval >0 ) + retval =-1 ;/* now signal fail; so retry can be done */ + +return retval; +} + +static s32 ttsp_spi_write_block_data (void *handle,u8 addr, +u8 length,const void *data) +{
drivers/input/touchscreen/cyttsp/cyttsp_spi.c line 200
Quoted 10 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c new file +10
-0+ struct cyttsp_spi *ts = container_of(handle, struct cyttsp_spi, ops); +int retval; + + retval =cyttsp_spi_xfer (CY_SPI_WR_OP , ts, addr, (void *)data, length); +if (retval <0 ) +dev_dbg (ts->ops.dev,"%s: ttsp_spi_write_block_data failed\n" , + __func__); + +if (retval == -EIO ) +return 0 ;
Why is -EIO special?
drivers/input/touchscreen/cyttsp/cyttsp_spi.c line 165
Quoted 4 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c new file +4
-0+else +return retval; +} +
Thanks.
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerRe: [PATCH 1/3] Input: cyttsp - Cypress TTSP capacitive multi-touch screen support
In reply to Javier Martinez CanillasHi Javier,
Quoted 8 lines · Javier Martinez Canillas
Cypress TrueTouch(tm) Standard Product controllers are found in a wide range of embedded devices. This driver add support for a variety of TTSP controllers.
The driver is composed of a core driver that process the data sent by the contacts and a set of bus specific interface modules. This patch adds the base core TTSP driver.
Quoted 6 lines
The original author of the driver is Kevin McNeely <[email protected]>
Since the hardware is capable of tracking identifiable contacts and the original driver used multi-touch protocol type A (stateless), multi-touch protocol type B (stateful) support was added by Javier Martinez Canillas.
Still reading through the patches, but have one question:
drivers/input/touchscreen/cyttsp/cyttsp_core.c line 812
Quoted 7 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +7
-0+ + ts->irq =gpio_to_irq (ts->platform_data->irq_gpio); +if (ts->irq <=0 ) { +dev_dbg (ts->dev,"%s: Error, failed to allocate irq\n" , + __func__); + goto error_init; + }
Why do we need to get gpio/irq from platform data instead of having board code set up controllers appropriately and use IRQ either from I2C client structure or from SPI?
Thanks.
Signature · 1 line
Dmitry
Re: [PATCH 1/3] Input: cyttsp - Cypress TTSP capacitive multi-touch screen support
Quoted 2 lines · Dmitry Torokhov
Hi Javier,
Hi Dmitry,
Thank you very much for the review.
Quoted 4 lines
Still reading through the patches, but have one question:
Quoted 9 lines
Why do we need to get gpio/irq from platform data instead of having board code set up controllers appropriately and use IRQ either from I2C client structure or from SPI?
Thanks.
--
Dmitry
The original author of this driver is Kevin McNeely (cc'ed in this patch submission).
I've only added multi-touch protocol type B support (which was a requirement for upstream acceptance) and resubmit the patch-set.
I think he will better answer your questions about the driver design.
Kevin?
Best regards,
Signature · 7 lines
Javier Martínez Canillas (+34) 682 39 81 69 Barcelona, Spain -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] Input: cyttsp - add support for Cypress TTSP touchscreen SPI bus interface
In reply to Dmitry TorokhovHello Dmitry,
Quoted 12 lines · Dmitry Torokhov
Hi Javier,
drivers/input/touchscreen/cyttsp/cyttsp_spi.c line 105
Quoted 5 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c new file +5
-0+ +memset ((void *)xfer,0 ,sizeof (xfer)); +spi_message_init (&msg); + xfer[0 ].tx_buf = wr_buf; + xfer[0 ].rx_buf = rd_buf;Since we are setting both TX and RX buffer here does this mean that the device will not work with controllers in half-duplex mode? What is the amount of data that will be placed in
rd_buf?
Both TX and RX buffers are set because Cypress requires full duplex operation always.
Quoted 8 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c line 122
Quoted 5 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c new file +5
-0+ retval =spi_sync_tmo (ts, &msg); +if (retval <0 ) { +dev_dbg (ts->ops.dev,"%s: spi sync error %d, len=%d, op=%d\n" , + __func__, retval, xfer[1 ].len, op); + retval =0 ;Why do we ignore the error?
Fixed: In next version a following ACK check code return the status to the cyttsp core so it can retry after waiting with an msleep() call.
Quoted 10 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c line 128
Quoted 6 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c new file +6
-0+ } + +if (op ==CY_SPI_RD_OP ) { +if ((rd_buf[CY_SPI_SYNC_BYTE ] ==CY_SPI_SYNC_ACK1 ) && + (rd_buf[CY_SPI_SYNC_BYTE +1 ] ==CY_SPI_SYNC_ACK2 )) + retval =0 ;What about write operation? Does the device send anything in
rd_buffor write command?
Fixed: Both read and write operations check the ACK bytes now.
Quoted 12 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c line 157
Quoted 8 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c new file +8
-0+ +if (op ==CY_SPI_RD_OP ) { +for (tries =CY_NUM_RETRY ; tries; tries--) { + retval =cyttsp_spi_xfer_ (op, ts, reg, buf, length); +if (retval ==0 ) +break ; +else +msleep (20 );Why do we need retry in SPI case but do not need it when device is connected via I2C? And not on writes?
Fixed: The retries now are made in the cyttsp core so it works both for SPI and I2C.
Quoted 6 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c line 200
Quoted 3 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c new file +3
-0+ +if (retval == -EIO ) +return 0 ;Why is
-EIOspecial?
Fixed: Now special EIO has been fixed to show meaning.
Quoted 9 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c line 165
Quoted 4 lines
drivers/input/touchscreen/cyttsp/cyttsp_spi.c new file +4
-0+else +return retval; +} +Thanks.
Signature · 1 line
Dmitry
Best regards,
Javier Martinez Canillas
Re: [PATCH 1/3] Input: cyttsp - Cypress TTSP capacitive multi-touch screen support
In reply to Dmitry TorokhovHello Dmitry,
Quoted 17 lines · Dmitry Torokhov
Hi Javier,
Still reading through the patches, but have one question:
drivers/input/touchscreen/cyttsp/cyttsp_core.c line 812
Quoted 7 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +7
-0+ + ts->irq =gpio_to_irq (ts->platform_data->irq_gpio); +if (ts->irq <=0 ) { +dev_dbg (ts->dev,"%s: Error, failed to allocate irq\n" , + __func__); + goto error_init; + }Why do we need to get gpio/irq from platform data instead of having board code set up controllers appropriately and use IRQ either from I2C client structure or from SPI?
Quoted 2 lines
Thanks.
Right, next version fix this by extracting the IRQ either from the I2C or SPI client data structure as you suggest.
Best regards,
Javier Martinez Canillas