Input: Cypress TTSP device driver
Subsystems (2)
PATCH v5 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.
---
v2: Fix issues called out by Dmitry Torokhov
- Extract the IRQ from the i2c client data and pass to cyttsp_core_init()
v3: Fix issues called out by Henrik Rydberg and Mohan Pallaka
- Remove bus type info since it is not used.
drivers/input/touchscreen/cyttsp/cyttsp_i2c.c | 190 +++++++++++++++++++++++++ 1 files changed, 190 insertions(+), 0 deletions(-) create mode 100644 drivers/input/touchscreen/cyttsp/cyttsp_i2c.c
drivers/input/touchscreen/cyttsp/cyttsp_i2c.c new file +190 -0
@@ -0,0 +1,190 @@ +/* +* Source for: +* Cypress TrueTouch(TM) Standard Product (TTSP) I2C touchscreen driver. +* For use with Cypress Txx3xx parts. +* Supported parts include: +* CY8CTST341 +* CY8CTMA340 +* +* Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc. +* Copyright (C) 2011 Javier Martinez Canillas <[email protected]> +* +* Multi-touch protocol type B support and cleanups by Javier Martinez Canillas +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2, and only version 2, as published by the +* Free Software Foundation. +* +* 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. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +* +* Contact Cypress Semiconductor at www.cypress.com <[email protected]> +* +*/ + +#include "cyttsp_core.h" + +#include <linux/i2c.h> +#include <linux/slab.h> + +#define CY_I2C_DATA_SIZE 128 + +struct cyttsp_i2c { +struct cyttsp_bus_ops ops; +struct i2c_client *client; +void *ttsp_client; +u8 wr_buf[CY_I2C_DATA_SIZE ]; +}; + +static s32 ttsp_i2c_read_block_data (void *handle,u8 addr, +u8 length,void *values) +{ + struct cyttsp_i2c *ts = container_of(handle, struct cyttsp_i2c, ops); +int retval =0 ; + + retval =i2c_master_send (ts->client, &addr,1 ); +if (retval <0 ) +return retval; + + retval =i2c_master_recv (ts->client, values, length); + +return (retval <0 ) ? retval :0 ; +} + +static s32 ttsp_i2c_write_block_data (void *handle,u8 addr, +u8 length,const void *values) +{ + struct cyttsp_i2c *ts = container_of(handle, struct cyttsp_i2c, ops); +int retval; + + ts->wr_buf[0 ] = addr; +memcpy (&ts->wr_buf[1 ], values, length); + + retval =i2c_master_send (ts->client, ts->wr_buf, length+1 ); + +return (retval <0 ) ? retval :0 ; +} + +static s32 ttsp_i2c_tch_ext (void *handle,void *values) +{ + struct cyttsp_i2c *ts = container_of(handle, struct cyttsp_i2c, ops); +int retval =0 ; + +/* +* TODO: Add custom touch extension handling code here +* set: retval < 0 for any returned system errors, +* retval = 0 if normal touch handling is required, +* retval > 0 if normal touch handling is *not* required +*/ +if (!ts || !values) + retval = -EINVAL ; + +return retval; +} + +static int __devinit cyttsp_i2c_probe (struct i2c_client *client, +const struct i2c_device_id *id) +{ +struct cyttsp_i2c *ts; + +if (!i2c_check_functionality (client->adapter,I2C_FUNC_I2C )) +return -EIO ; + +/* allocate and clear memory */ + ts =kzalloc (sizeof (*ts),GFP_KERNEL ); +if (!ts) { +dev_dbg (&client->dev,"%s: Error, kzalloc.\n" , __func__); +return -ENOMEM ; + } + +/* register driver_data */ + ts->client = client; +i2c_set_clientdata (client, ts); + ts->ops.write = ttsp_i2c_write_block_data; + ts->ops.read = ttsp_i2c_read_block_data; + ts->ops.ext = ttsp_i2c_tch_ext; + ts->ops.dev = &client->dev; + + ts->ttsp_client =cyttsp_core_init (&ts->ops, &client->dev, client->irq); +if (IS_ERR (ts->ttsp_client)) { +int retval =PTR_ERR (ts->ttsp_client); +kfree (ts); +return retval; + } + +dev_dbg (ts->ops.dev,"%s: Registration complete\n" , __func__); + +return 0 ; +} + + +/* registered in driver struct */ +static int __devexit cyttsp_i2c_remove(struct i2c_client *client) +{ +struct cyttsp_i2c *ts; + + ts =i2c_get_clientdata (client); +cyttsp_core_release (ts->ttsp_client); +kfree (ts); +return 0 ; +} + +#ifdef CONFIG_PM +static int cyttsp_i2c_suspend (struct i2c_client *client,pm_message_t message) +{ +struct cyttsp_i2c *ts =i2c_get_clientdata (client); + +return cyttsp_suspend (ts->ttsp_client); +} + +static int cyttsp_i2c_resume (struct i2c_client *client) +{ +struct cyttsp_i2c *ts =i2c_get_clientdata (client); + +return cyttsp_resume (ts->ttsp_client); +} +#endif + +static const struct i2c_device_id cyttsp_i2c_id[] = { + {CY_I2C_NAME ,0 }, { } +}; + +static struct i2c_driver cyttsp_i2c_driver = { + .driver = { + .name =CY_I2C_NAME , + .owner =THIS_MODULE , + }, + .probe = cyttsp_i2c_probe, + .remove =__devexit_p (cyttsp_i2c_remove), + .id_table = cyttsp_i2c_id, +#ifdef CONFIG_PM + .suspend = cyttsp_i2c_suspend, + .resume = cyttsp_i2c_resume, +#endif +}; + +static int __init cyttsp_i2c_init (void ) +{ +return i2c_add_driver (&cyttsp_i2c_driver); +} + +static void __exit cyttsp_i2c_exit(void) +{ +return i2c_del_driver (&cyttsp_i2c_driver); +} + +module_init (cyttsp_i2c_init); +module_exit (cyttsp_i2c_exit); + +MODULE_ALIAS ("i2c:cyttsp" ); +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("Cypress TrueTouch(R) Standard Product (TTSP) I2C driver" ); +MODULE_AUTHOR ("Cypress" ); +MODULE_DEVICE_TABLE (i2c, cyttsp_i2c_id);
Signature · 1 line
1.7.4.1
v5 cover Input: Cypress TTSP device driver
Cypress TrueTouch(tm) Standard Product controllers are found in a wide range of embedded devices. This patch-set 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).
This is a fifth version of the driver that fixes issues called out by Dmitry Torokhov, Henrik Rydberg and Mohan Pallaka and Kevin McNeely.
The patchset is composed of the patches:
[PATCH v5 1/3] Input: cyttsp - Cypress TTSP capacitive multi-touch screen support [PATCH v5 2/3] Input: cyttsp - add support for Cypress TTSP touchscreen I2C bus interface [PATCH v5 3/3] Input: cyttsp - add support for Cypress TTSP touchscreen SPI bus interface
PATCH v5 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.
Since the hardware is capable of tracking identifiable contacts, multi-touch protocol type B (stateful) is used to report contact information.
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.
---
v2: Fix issues called out by Dmitry Torokhov
- Add msleep() delays between retries for read and write operations.
- Change cyttsp_core_init() to receive the IRQ from the client data instead of obtaining from the platform_data.
v3: Fix issues called out by Henrik Rydberg and Mohan Pallaka
- Map each possible track id to a multitouch input slot.
- Remove bus type info since it is not used.
- Add retry logic to ttsp_write_block_data().
- ttsp_read_block_data() already msleep() remove the sleep in the caller.
- cyttsp_xy_worker() sounds as if it's a workqueue, change the function name.
- Check if handle is NULL in cyttsp_resume().
- Use platform data's use_sleep to decide to go deep sleep or low power mode.
- input_register_device() error path has to call input_free_device().
v4: Fix issues called out by Henrik Rydberg
- Remove unnecesary code and cleanup contact handler since input core is able to detect duplicates.
v5: Fix issues called out by Henrik Rydberg
- Cleanup ttsp_[read | write]_block_data functions.
- Remove unused code to handle extended touch data.
- Simplify code in cyttsp_bl_app_data() and cyttsp_soft_reset().
drivers/input/touchscreen/Kconfig | 2 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/cyttsp/Kconfig | 36 + drivers/input/touchscreen/cyttsp/Makefile | 3 + drivers/input/touchscreen/cyttsp/cyttsp_core.c | 828 ++++++++++++++++++++++++ drivers/input/touchscreen/cyttsp/cyttsp_core.h | 60 ++ include/linux/input/cyttsp.h | 71 ++ 7 files changed, 1001 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 +36 -0
@@ -0,0 +1,36 @@ +config TOUCHSCREEN_CYTTSP_CORE + tristate "Cypress TTSP touchscreen core" + depends on INPUT_TOUCHSCREEN + help + Say Y here if you have a touchscreen interface using one + controller from the Cypress TrueTouch(tm) Standard Product + family. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called cyttsp_core. + +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. + +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 new file +3 -0
@@ -0,0 +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_core.c new file +828 -0
828 lines not on this page · raw message
drivers/input/touchscreen/cyttsp/cyttsp_core.h new file +60 -0
60 lines not on this page · raw message
include/linux/input/cyttsp.h new file +71 -0
71 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH v5 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 I2C bus interface.
---
v2: Fix issues called out by Dmitry Torokhov
- Extract the IRQ from the spi client data and pass to cyttsp_core_init()
- Remove the extra retries and limit the retries to the cyttsp_core.c read/write block functions.
- Cleanup cyttsp_spi_xfer(), check ACK in write operation and fix special EIO case to show its meaning.
v3: Fix issues called out by Henrik Rydberg and Mohan Pallaka
- Remove bus type info since it is not used.
drivers/input/touchscreen/cyttsp/cyttsp_spi.c | 295 +++++++++++++++++++++++++ 1 files changed, 295 insertions(+), 0 deletions(-) create mode 100644 drivers/input/touchscreen/cyttsp/cyttsp_spi.c
drivers/input/touchscreen/cyttsp/cyttsp_spi.c new file +295 -0
@@ -0,0 +1,295 @@ +/* +* Source for: +* Cypress TrueTouch(TM) Standard Product (TTSP) SPI touchscreen driver. +* For use with Cypress Txx3xx parts. +* Supported parts include: +* CY8CTST341 +* CY8CTMA340 +* +* Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc. +* Copyright (C) 2011 Javier Martinez Canillas <[email protected]> +* +* Multi-touch protocol type B support and cleanups by Javier Martinez Canillas +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2, and only version 2, as published by the +* Free Software Foundation. +* +* 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. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +* +* Contact Cypress Semiconductor at www.cypress.com <[email protected]> +* +*/ + +#include "cyttsp_core.h" + +#include <linux/spi/spi.h> +#include <linux/delay.h> + +#define CY_SPI_WR_OP 0x00/* r/~w */ +#define CY_SPI_RD_OP 0x01 +#define CY_SPI_CMD_BYTES 4 +#define CY_SPI_SYNC_BYTE 2 +#define CY_SPI_SYNC_ACK1 0x62/* from protocol v.2 */ +#define CY_SPI_SYNC_ACK2 0x9D/* from protocol v.2 */ +#define CY_SPI_DATA_SIZE 128 +#define CY_SPI_DATA_BUF_SIZE (CY_SPI_CMD_BYTES + CY_SPI_DATA_SIZE) +#define CY_SPI_BITS_PER_WORD 8 + +struct cyttsp_spi { +struct cyttsp_bus_ops bus_ops; +struct spi_device *spi_client; +void *ttsp_client; +u8 wr_buf[CY_SPI_DATA_BUF_SIZE ]; +u8 rd_buf[CY_SPI_DATA_BUF_SIZE ]; +}; + +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->bus_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 */ + 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); + +/* +We set both TX and RX buffers because Cypress TTSP +requires full duplex operation. +*/ + xfer[0 ].tx_buf = wr_buf; + xfer[0 ].rx_buf = rd_buf; +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); + + xfer[1 ].rx_buf = buf; + xfer[1 ].len = length; +spi_message_add_tail (&xfer[1 ], &msg); + } + + retval =spi_sync (ts->spi_client, &msg); +if (retval <0 ) { +dev_dbg (ts->bus_ops.dev, +"%s: spi_sync() error %d, len=%d, op=%d\n" , + __func__, retval, xfer[1 ].len, op); + +/* +* do not return here since was a bad ACK sequence +* let the following ACK check handle any errors and +* allow silent retries +*/ + } + +if ((rd_buf[CY_SPI_SYNC_BYTE ] ==CY_SPI_SYNC_ACK1 ) && + (rd_buf[CY_SPI_SYNC_BYTE +1 ] ==CY_SPI_SYNC_ACK2 )) + retval =0 ; +else { +int i; +for (i =0 ; i < (CY_SPI_CMD_BYTES ); i++) +dev_dbg (ts->bus_ops.dev, +"%s: test rd_buf[%d]:0x%02x\n" , + __func__, i, rd_buf[i]); +for (i =0 ; i < (length); i++) +dev_dbg (ts->bus_ops.dev, +"%s: test buf[%d]:0x%02x\n" , + __func__, i, buf[i]); + +/* signal ACK error so silent retry */ + retval =1 ; + } + +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, bus_ops); +int retval; + + retval =cyttsp_spi_xfer (CY_SPI_RD_OP , ts, addr, data, length); +if (retval <0 ) +pr_err ("%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 = -EIO ;/* 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) +{ +struct cyttsp_spi *ts = + container_of(handle, struct cyttsp_spi, bus_ops); +int retval; + + retval =cyttsp_spi_xfer (CY_SPI_WR_OP , ts, addr, (void *)data, length); +if (retval <0 ) +pr_err ("%s: ttsp_spi_write_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 = -EIO ;/* now signal fail; so retry can be done */ + +return retval; +} + +static s32 ttsp_spi_tch_ext (void *handle,void *values) +{ +struct cyttsp_spi *ts = + container_of(handle, struct cyttsp_spi, bus_ops); +int retval =0 ; + +/* +* TODO: Add custom touch extension handling code here +* set: retval < 0 for any returned system errors, +* retval = 0 if normal touch handling is required, +* retval > 0 if normal touch handling is *not* required +*/ + +if (!ts || !values) + retval = -EINVAL ; + +return retval; +} + +static int __devinit cyttsp_spi_probe (struct spi_device *spi) +{ +struct cyttsp_spi *ts; +int retval; + +/* Set up SPI*/ + spi->bits_per_word =CY_SPI_BITS_PER_WORD ; + spi->mode =SPI_MODE_0 ; + retval =spi_setup (spi); +if (retval <0 ) { +dev_dbg (&spi->dev,"%s: SPI setup error %d\n" , + __func__, retval); +return retval; + } + + ts =kzalloc (sizeof (*ts),GFP_KERNEL ); +if (!ts) { +dev_dbg (&spi->dev,"%s: Error, kzalloc\n" , __func__); +return -ENOMEM ; + } + + ts->spi_client = spi; +dev_set_drvdata (&spi->dev, ts); + ts->bus_ops.write = ttsp_spi_write_block_data; + ts->bus_ops.read = ttsp_spi_read_block_data; + ts->bus_ops.ext = ttsp_spi_tch_ext; + ts->bus_ops.dev = &spi->dev; + + ts->ttsp_client =cyttsp_core_init (&ts->bus_ops, &spi->dev, spi->irq); +if (IS_ERR (ts->ttsp_client)) { +int retval =PTR_ERR (ts->ttsp_client); +kfree (ts); +return retval; + } + +dev_dbg (ts->bus_ops.dev,"%s: Registration complete\n" , __func__); + +return 0 ; +} + +static int __devexit cyttsp_spi_remove(struct spi_device *spi) +{ +struct cyttsp_spi *ts =dev_get_drvdata (&spi->dev); + +cyttsp_core_release (ts->ttsp_client); +kfree (ts); +return 0 ; +} + +#ifdef CONFIG_PM +static int cyttsp_spi_suspend (struct spi_device *spi,pm_message_t message) +{ +struct cyttsp_spi *ts =dev_get_drvdata (&spi->dev); + +return cyttsp_suspend (ts->ttsp_client); +} + +static int cyttsp_spi_resume (struct spi_device *spi) +{ +struct cyttsp_spi *ts =dev_get_drvdata (&spi->dev); + +return cyttsp_resume (ts->ttsp_client); +} +#endif + +static struct spi_driver cyttsp_spi_driver = { + .driver = { + .name =CY_SPI_NAME , + .owner =THIS_MODULE , + }, + .probe = cyttsp_spi_probe, + .remove =__devexit_p (cyttsp_spi_remove), +#ifdef CONFIG_PM + .suspend = cyttsp_spi_suspend, + .resume = cyttsp_spi_resume, +#endif +}; + +static int __init cyttsp_spi_init (void ) +{ +return spi_register_driver (&cyttsp_spi_driver); +} +module_init (cyttsp_spi_init); + +static void __exit cyttsp_spi_exit(void) +{ +spi_unregister_driver (&cyttsp_spi_driver); +} +module_exit (cyttsp_spi_exit); + +MODULE_ALIAS ("spi:cyttsp" ); +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("Cypress TrueTouch(R) Standard Product (TTSP) SPI driver" ); +MODULE_AUTHOR ("Cypress" ); +
Signature · 1 line
1.7.4.1
Re: [PATCH v5 2/3] Input: cyttsp - add support for Cypress TTSP touchscreen I2C bus interface
In reply to a message not in the archiveQuoted 4 lines · Shubhrajyoti Datta
Hello Martinez,
Some small comments.
Hi Shubhrajyoti,
Thanks for the review.
Quoted 87 lines
Quoted 85 lines · Javier Martinez Canillas
The driver is composed of a core driver that process the data sent by the contacts and a set of bus specific interface modules.
Signed-off-by Javier Martinez Canillas <[email protected]>---
v2: Fix issues called out by Dmitry Torokhov
- Extract the IRQ from the i2c client data and pass tocyttsp_core_init()v3: Fix issues called out by Henrik Rydberg and Mohan Pallaka
- Remove bus type info since it is not used.drivers/input/touchscreen/cyttsp/cyttsp_i2c.c | 190
+++++++++++++++++++++++++1 files changed, 190 insertions(+), 0 deletions(-)create mode 100644
drivers/input/touchscreen/cyttsp/cyttsp_i2c.cdrivers/input/touchscreen/cyttsp/cyttsp_i2c.c new file +10
-0@@ -0,0 +1,190 @@ +/* +* Source for: +* Cypress TrueTouch(TM) Standard Product (TTSP) I2C touchscreen driver. +* For use with Cypress Txx3xx parts. +* Supported parts include: +* CY8CTST341 +* CY8CTMA340 +* +* Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc. +* Copyright (C) 2011 Javier Martinez Canillas <[email protected]>
+ *
+ * Multi-touch protocol type B support and cleanups by Javier Martinez Canillas
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2, and only version 2, as published by the
+ * Free Software Foundation.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contact Cypress Semiconductor at www.cypress.com <[email protected]>
+ *
+ */drivers/input/touchscreen/cyttsp/cyttsp_i2c.c new file +19
-0+ +#include "cyttsp_core.h" + +#include <linux/i2c.h> +#include <linux/slab.h> + +#define CY_I2C_DATA_SIZE 128 + +struct cyttsp_i2c { + struct cyttsp_bus_ops ops; + struct i2c_client *client; + void *ttsp_client; + u8 wr_buf[CY_I2C_DATA_SIZE]; +}; + +static s32 ttsp_i2c_read_block_data (void *handle,u8 addr, + u8 length, void *values) +{ + struct cyttsp_i2c *ts = container_of(handle, struct cyttsp_i2c,ops);
+ int retval = 0;
+
+ retval =i2c_master_send(ts->client, &addr, 1);
+ if (retval < 0)
+ return retval;
Quoted 8 lines
drivers/input/touchscreen/cyttsp/cyttsp_i2c.c line 58
Quoted 4 lines
drivers/input/touchscreen/cyttsp/cyttsp_i2c.c new file +4
-0+ + retval = i2c_master_recv(ts->client, values, length); + + return (retval < 0) ? retval : 0;Trivial comment:
Could we check the bytes written ?
Feel free to ignore if you feel so.
Yes, you are right. I also think that I should check if retval == length and return an error code otherwise.
Quoted 111 lines
Quoted 111 lines
drivers/input/touchscreen/cyttsp/cyttsp_i2c.c new file +6
-0+} + +static s32 ttsp_i2c_write_block_data (void *handle,u8 addr, + u8 length, const void *values) +{ + struct cyttsp_i2c *ts = container_of(handle, struct cyttsp_i2c,ops);
+ int retval;drivers/input/touchscreen/cyttsp/cyttsp_i2c.c new file +12
-0+ + ts->wr_buf[0] = addr; + memcpy(&ts->wr_buf[1], values, length); + + retval = i2c_master_send(ts->client, ts->wr_buf, length+1); + + return (retval < 0) ? retval : 0; +} + +static s32 ttsp_i2c_tch_ext (void *handle,void *values) +{ + struct cyttsp_i2c *ts = container_of(handle, struct cyttsp_i2c,ops);
+ int retval = 0;drivers/input/touchscreen/cyttsp/cyttsp_i2c.c new file +37
-0+ + /* + * TODO: Add custom touch extension handling code here + * set: retval < 0 for any returned system errors, + * retval = 0 if normal touch handling is required, + * retval > 0 if normal touch handling is *not* required + */ + if (!ts || !values) + retval = -EINVAL; + + return retval; +} + +static int __devinit cyttsp_i2c_probe (struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct cyttsp_i2c *ts; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) + return -EIO; + + /* allocate and clear memory */ + ts = kzalloc(sizeof(*ts), GFP_KERNEL); + if (!ts) { + dev_dbg(&client->dev, "%s: Error, kzalloc.\n", __func__); + return -ENOMEM; + } + + /* register driver_data */ + ts->client = client; + i2c_set_clientdata(client, ts); + ts->ops.write = ttsp_i2c_write_block_data; + ts->ops.read = ttsp_i2c_read_block_data; + ts->ops.ext = ttsp_i2c_tch_ext; + ts->ops.dev = &client->dev; + + ts->ttsp_client = cyttsp_core_init(&ts->ops, &client->dev,
client->irq);
+ if (IS_ERR(ts->ttsp_client)) {
+ int retval =PTR_ERR(ts->ttsp_client);
+ kfree(ts);
+ return retval;
+ }drivers/input/touchscreen/cyttsp/cyttsp_i2c.c new file +20
-0+ + dev_dbg(ts->ops.dev, "%s: Registration complete\n", __func__); + + return 0; +} + + +/* registered in driver struct */ +static int __devexit cyttsp_i2c_remove(struct i2c_client *client) +{ + struct cyttsp_i2c *ts; + + ts = i2c_get_clientdata(client); + cyttsp_core_release(ts->ttsp_client); + kfree(ts); + return 0; +} + +#ifdef CONFIG_PM +static int cyttsp_i2c_suspend(struct i2c_client *client, pm_message_tmessage)
drivers/input/touchscreen/cyttsp/cyttsp_i2c.c new file +24
-0+{ + struct cyttsp_i2c *ts = i2c_get_clientdata(client); + + return cyttsp_suspend(ts->ttsp_client); +} + +static int cyttsp_i2c_resume (struct i2c_client *client) +{ + struct cyttsp_i2c *ts = i2c_get_clientdata(client); + + return cyttsp_resume(ts->ttsp_client); +} +#endif + +static const struct i2c_device_id cyttsp_i2c_id[] = { + { CY_I2C_NAME, 0 }, { } +}; + +static struct i2c_driver cyttsp_i2c_driver = { + .driver = { + .name = CY_I2C_NAME, + .owner = THIS_MODULE, + }, + .probe = cyttsp_i2c_probe,
Quoted 8 lines
drivers/input/touchscreen/cyttsp/cyttsp_i2c.c line 170
Quoted 6 lines
+ .remove =
__devexit_p(cyttsp_i2c_remove),
+ .id_table =cyttsp_i2c_id,drivers/input/touchscreen/cyttsp/cyttsp_i2c.c new file +4
-0+#ifdef CONFIG_PM + .suspend = cyttsp_i2c_suspend, + .resume = cyttsp_i2c_resume, +#endif How about moving to dev pm ops ?
Yes, I can move there.
Thank you for your comments, probably Henrik and others find issues too. I will include these two in the next version of the driver.
Quoted 25 lines
Quoted 25 lines
drivers/input/touchscreen/cyttsp/cyttsp_i2c.c new file +18
-0+}; + +static int __init cyttsp_i2c_init (void ) +{ + return i2c_add_driver(&cyttsp_i2c_driver); +} + +static void __exit cyttsp_i2c_exit(void) +{ + return i2c_del_driver(&cyttsp_i2c_driver); +} + +module_init (cyttsp_i2c_init); +module_exit (cyttsp_i2c_exit); + +MODULE_ALIAS ("i2c:cyttsp" ); +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION("Cypress TrueTouch(R) Standard Product (TTSP) I2Cdriver");
drivers/input/touchscreen/cyttsp/cyttsp_i2c.c new file +2
-1+MODULE_AUTHOR ("Cypress" ); +MODULE_DEVICE_TABLE (i2c, cyttsp_i2c_id); --1.7.4.1
Quoted 6 lines
Quoted 4 lines
--
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
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
Quoted 13 lines · Javier Martinez Canillas
Cypress TrueTouch(tm) Standard Product controllers are found in a wide range of embedded devices. This patch-set 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).
Quoted 9 lines
This is a fifth version of the driver that fixes issues called out by Dmitry Torokhov, Henrik Rydberg and Mohan Pallaka and Kevin McNeely.
The patchset is composed of the patches:
[PATCH v5 1/3] Input: cyttsp - Cypress TTSP capacitive multi-touch screen support [PATCH v5 2/3] Input: cyttsp - add support for Cypress TTSP touchscreen I2C bus interface [PATCH v5 3/3] Input: cyttsp - add support for Cypress TTSP touchscreen SPI bus interface
Hi Henrik,
Any feedback from this patch-set?
Thank you and 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 v5 1/3] Input: cyttsp - Cypress TTSP capacitive multi-touch screen support
In reply to Javier Martinez CanillasHi Javier,
some more comments on the code. Presumable Dmitry will have additional ones later on. Thank you for your patience.
drivers/input/touchscreen/cyttsp/cyttsp_core.c line 73
Quoted 3 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +3
-0+/* Slots management */ +#define CY_MAX_FINGER 4 +#define CY_MAX_ID 15
I realize the firmware reports ids in the range [1..14], but it is not visible from the code. Allowing all 16 values makes correctness obvious.
drivers/input/touchscreen/cyttsp/cyttsp_core.c line 210
Quoted 13 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +13
-0+static int cyttsp_load_bl_regs (struct cyttsp *ts) +{ +int retval; + +memset (&(ts->bl_data),0 ,sizeof (struct cyttsp_bootloader_data )); + + ts->bl_data.bl_status =0x10 ; + + retval =ttsp_read_block_data (ts,CY_REG_BASE , +sizeof (ts->bl_data), &(ts->bl_data)); + +return retval; +}
Looks like you missed the removal of retval here.
Quoted 33 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +33
-0+ +static int cyttsp_bl_app_valid (struct cyttsp *ts) +{ +int retval; + + retval =cyttsp_load_bl_regs (ts); + +if (retval <0 ) { + retval = -ENODEV ; + goto done; + } + +if (GET_BOOTLOADERMODE (ts->bl_data.bl_status)) { +if (IS_VALID_APP (ts->bl_data.bl_status)) { +dev_dbg (ts->dev,"%s: App found; normal boot\n" , + __func__); +return 0 ; + }else { +dev_dbg (ts->dev,"%s: NO APP; load firmware!!\n" , + __func__); +return -ENODEV ; + } + } + +if (GET_HSTMODE (ts->bl_data.bl_file) ==CY_OPERATE_MODE ) { +if (!(IS_OPERATIONAL_ERR (ts->bl_data.bl_status))) { +dev_dbg (ts->dev,"%s: Operational\n" , + __func__); +return 1 ; + }else { +dev_dbg (ts->dev,"%s: Operational failure\n" , + __func__); +return -ENODEV ;
drivers/input/touchscreen/cyttsp/cyttsp_core.c line 253
Quoted 10 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +10
-0+ } + } + +dev_dbg (ts->dev,"%s: Non-Operational failure\n" , + __func__); + retval = -ENODEV ; +done: +return retval; + +}
Are the debug paths still necessary? There are a lot of them.
Quoted 32 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +32
-0+static int cyttsp_exit_bl_mode (struct cyttsp *ts) +{ +int retval; +int tries; +u8 bl_cmd[sizeof (bl_command)]; + +memcpy (bl_cmd, bl_command,sizeof (bl_command)); +if (ts->platform_data->bl_keys) +memcpy (&bl_cmd[sizeof (bl_command) -CY_NUM_BL_KEYS ], + ts->platform_data->bl_keys,sizeof (bl_command)); + +dev_dbg (ts->dev, +"%s: bl_cmd= " +"%02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n" , + __func__, bl_cmd[0 ], bl_cmd[1 ], bl_cmd[2 ], + bl_cmd[3 ], bl_cmd[4 ], bl_cmd[5 ], bl_cmd[6 ], + bl_cmd[7 ], bl_cmd[8 ], bl_cmd[9 ], bl_cmd[10 ]); + + retval =ttsp_write_block_data (ts,CY_REG_BASE , +sizeof (bl_cmd), (void *)bl_cmd); +if (retval <0 ) +return retval; + +/* wait for TTSP Device to complete switch to Operational mode */ + tries =0 ; +do { +msleep (CY_DELAY_DFLT ); + retval =cyttsp_load_bl_regs (ts); + }while (!((retval ==0 ) && + !GET_BOOTLOADERMODE (ts->bl_data.bl_status)) && + (tries++ <CY_DELAY_MAX )); +
drivers/input/touchscreen/cyttsp/cyttsp_core.c line 296
Quoted 10 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +10
-0+dev_dbg (ts->dev,"%s: check bl ready tries=%d ret=%d stat=%02X\n" , + __func__, tries, retval, ts->bl_data.bl_status); + +if (retval <0 ) +return retval; +else if (GET_BOOTLOADERMODE (ts->bl_data.bl_status)) +return -ENODEV ; +else +return 0 ; +}
Regardless of if it can ever happen, programatically the (retval > 0) && GET_BOOTLOADERMODE(ts->bl_data.bl_status) case is slipping through here.
Quoted 16 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +16
-0+static int cyttsp_set_operational_mode(struct cyttsp *ts) +{ + struct cyttsp_xydata xy_data; + int retval; + int tries; + u8 cmd = CY_OPERATE_MODE; + + retval = ttsp_write_block_data(ts, CY_REG_BASE, sizeof(cmd), &cmd); + + if (retval < 0) + return retval; + + /* wait for TTSP Device to complete switch to Operational mode */ + tries = 0; + do { + retval = ttsp_read_block_data(ts, CY_REG_BASE,
drivers/input/touchscreen/cyttsp/cyttsp_core.c line 323
Quoted 10 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +10
-0+ sizeof(xy_data), &(xy_data)); + }while (!((retval ==0 ) && + (xy_data.act_dist ==CY_ACT_DIST_DFLT )) && + (tries++ <CY_DELAY_MAX )); + +dev_dbg (ts->dev,"%s: check op ready tries=%d ret=%d dist=%02X\n" , + __func__, tries, retval, xy_data.act_dist); + +return retval; +}
So (xy_data.act_dist == CY_ACT_DIST_DFL) here is not an error?
Quoted 13 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +13
-0+static int cyttsp_set_sysinfo_mode (struct cyttsp *ts) +{ +int retval; +int tries; +u8 cmd =CY_SYSINFO_MODE ; + +memset (&(ts->sysinfo_data),0 ,sizeof (struct cyttsp_sysinfo_data )); + +/* switch to sysinfo mode */ + retval =ttsp_write_block_data (ts,CY_REG_BASE ,sizeof (cmd), &cmd); +if (retval <0 ) +return retval; +
drivers/input/touchscreen/cyttsp/cyttsp_core.c line 347
Quoted 10 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +10
-0+/* read sysinfo registers */ + tries =0 ; +do { +msleep (CY_DELAY_DFLT ); + retval =ttsp_read_block_data (ts,CY_REG_BASE , +sizeof (ts->sysinfo_data), &(ts->sysinfo_data)); + }while (!((retval ==0 ) && + !((ts->sysinfo_data.tts_verh ==0 ) && + (ts->sysinfo_data.tts_verl ==0 ))) && + (tries++ <CY_DELAY_MAX ));
Expands to (retval || !ts->sysinfo_data.tts_verh && !ts->sysinfo_data.tts_verl) && (tries++ < CY_DELAY_MAX), which seems a bit simpler to me. Also, &ts->sysinfo_data could be a pointer here.
Coding verh+verl as a 16-bit value?
Are the timeouted (tries >= CY_DELAY_MAX) cases not errors here either?
<snip>
Quoted 6 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +6
-0+static int cyttsp_soft_reset (struct cyttsp *ts) +{ +int retval; +u8 cmd =CY_SOFT_RESET_MODE ; +long wait_jiffies =msecs_to_jiffies (CY_DELAY_DFLT *CY_DELAY_MAX ); +/* wait for interrupt to set ready completion */
drivers/input/touchscreen/cyttsp/cyttsp_core.c line 403
Quoted 10 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +10
-0+INIT_COMPLETION (ts->bl_ready); + + retval =ttsp_write_block_data (ts,CY_REG_BASE ,sizeof (cmd), &cmd); +if (retval <0 ) +return retval; + + retval =wait_for_completion_timeout (&ts->bl_ready, wait_jiffies); + +if (retval >0 ) + retval =0 ;
Seems this one slipped.
drivers/input/touchscreen/cyttsp/cyttsp_core.c line 428
Quoted 12 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +12
-0+ +return retval; +} + +static int cyttsp_hndshk (struct cyttsp *ts,u8 hst_mode) +{ +int retval; +u8 cmd; + + cmd = hst_mode &CY_HNDSHK_BIT ? + hst_mode ^CY_HNDSHK_BIT : + hst_mode |CY_HNDSHK_BIT ;
Whoa, please redo this one correctly.
Quoted 4 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +4
-0+ + retval =ttsp_write_block_data (ts,CY_REG_BASE , +sizeof (cmd), (u8 *)&cmd); +
drivers/input/touchscreen/cyttsp/cyttsp_core.c line 653
Quoted 10 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +9
-0+return retval; +} +int cyttsp_resume (void *handle) +{ +struct cyttsp *ts = handle; +int retval =0 ; +struct cyttsp_xydata xydata; + +if (ts) {
Neater if returning on (!ts) here instead.
Quoted 17 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +17
-0+if (ts->platform_data->use_sleep && (ts->power_state != +CY_ACTIVE_STATE )) { +if (ts->platform_data->wakeup) { + retval = ts->platform_data->wakeup (); +if (retval <0 ) +dev_dbg (ts->dev,"%s: Error, wakeup failed!\n" , + __func__); + }else { +dev_dbg (ts->dev,"%s: Error, wakeup not implemented " +"(check board file).\n" , __func__); + retval = -ENOSYS ; + } +if (!(retval <0 )) { + retval =ttsp_read_block_data (ts,CY_REG_BASE , +sizeof (xydata), + &xydata); + if (!(retval < 0) &&
drivers/input/touchscreen/cyttsp/cyttsp_core.c line 680
Quoted 10 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +10
-0+ !GET_HSTMODE(xydata.hst_mode)) + ts->power_state =CY_ACTIVE_STATE ; + } + } +dev_dbg (ts->dev,"%s: Wake Up %s\n" , __func__, + (retval <0 ) ?"FAIL" :"PASS" ); + } +return retval; +} +EXPORT_SYMBOL_GPL (cyttsp_resume);
Thanks.
Henrik
Re: [PATCH v5 1/3] Input: cyttsp - Cypress TTSP capacitive multi-touch screen support
Quoted 5 lines · Henrik Rydberg
Hi Javier,
some more comments on the code. Presumable Dmitry will have additional ones later on. Thank you for your patience.
Hi Henrik,
Thank for your patience. Sorry for all the iterations.
Quoted 8 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c line 73
Quoted 3 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +3
-0+/* Slots management */ +#define CY_MAX_FINGER 4 +#define CY_MAX_ID 15I realize the firmware reports ids in the range [1..14], but it is not visible from the code. Allowing all 16 values makes correctness obvious.
Ok, I'll change to: #define CY_MAX_ID 16.
Quoted 7 lines
Quoted 7 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +7
-0+static int cyttsp_load_bl_regs (struct cyttsp *ts) +{ + int retval; + + memset(&(ts->bl_data), 0, sizeof(struct cyttsp_bootloader_data)); + + ts->bl_data.bl_status = 0x10;
Quoted 9 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c line 210
Quoted 6 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +6
-0+ + retval = ttsp_read_block_data(ts, CY_REG_BASE, + sizeof(ts->bl_data), &(ts->bl_data)); + + return retval; +}Looks like you missed the removal of retval here.
Yes, sorry. I'll change to return ttsp_read_block_data() so I can get rid of the retval here.
Quoted 37 lines
Quoted 37 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +37
-0+ +static int cyttsp_bl_app_valid (struct cyttsp *ts) +{ + int retval; + + retval = cyttsp_load_bl_regs(ts); + + if (retval < 0) { + retval = -ENODEV; + goto done; + } + + if (GET_BOOTLOADERMODE(ts->bl_data.bl_status)) { + if (IS_VALID_APP(ts->bl_data.bl_status)) { + dev_dbg(ts->dev, "%s: App found; normal boot\n", + __func__); + return 0; + } else { + dev_dbg(ts->dev, "%s: NO APP; load firmware!!\n", + __func__); + return -ENODEV; + } + } + + if (GET_HSTMODE(ts->bl_data.bl_file) == CY_OPERATE_MODE) { + if (!(IS_OPERATIONAL_ERR(ts->bl_data.bl_status))) { + dev_dbg(ts->dev, "%s: Operational\n", + __func__); + return 1; + } else { + dev_dbg(ts->dev, "%s: Operational failure\n", + __func__); + return -ENODEV; + } + } + + dev_dbg(ts->dev, "%s: Non-Operational failure\n",
Quoted 9 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c line 253
Quoted 6 lines
+
__func__);
+ retval =-ENODEV;drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +4
-0+done: + return retval; + +}Are the debug paths still necessary? There are a lot of them.
No I think there are not necessary any more, I'll remove them. It will make the code cleaner.
Quoted 37 lines
Quoted 37 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +37
-0+static int cyttsp_exit_bl_mode (struct cyttsp *ts) +{ + int retval; + int tries; + u8 bl_cmd[sizeof(bl_command)]; + + memcpy(bl_cmd, bl_command, sizeof(bl_command)); + if (ts->platform_data->bl_keys) + memcpy(&bl_cmd[sizeof(bl_command) - CY_NUM_BL_KEYS], + ts->platform_data->bl_keys, sizeof(bl_command)); + + dev_dbg(ts->dev, + "%s: bl_cmd= " + "%02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n", + __func__, bl_cmd[0], bl_cmd[1], bl_cmd[2], + bl_cmd[3], bl_cmd[4], bl_cmd[5], bl_cmd[6], + bl_cmd[7], bl_cmd[8], bl_cmd[9], bl_cmd[10]); + + retval = ttsp_write_block_data(ts, CY_REG_BASE, + sizeof(bl_cmd), (void *)bl_cmd); + if (retval < 0) + return retval; + + /* wait for TTSP Device to complete switch to Operational mode */ + tries = 0; + do { + msleep(CY_DELAY_DFLT); + retval = cyttsp_load_bl_regs(ts); + } while (!((retval == 0) && + !GET_BOOTLOADERMODE(ts->bl_data.bl_status)) && + (tries++ < CY_DELAY_MAX)); + + dev_dbg(ts->dev, "%s: check bl ready tries=%d ret=%d stat=%02X\n", + __func__, tries, retval, ts->bl_data.bl_status); + + if (retval < 0) + return retval;
Quoted 9 lines
Quoted 5 lines
+ else if (
GET_BOOTLOADERMODE(ts->bl_data.bl_status))
+ return-ENODEV;
+ else
+ return 0;
+}Regardless of if it can ever happen, programatically the (retval > 0) &&
GET_BOOTLOADERMODE(ts->bl_data.bl_status)case is slipping through here.
Good question. I think it can happen if the read succeed and the device is still in bootloader mode. But I don't know the hardware enough to confirm that.
Kevin?
Quoted 20 lines
Quoted 20 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +20
-0+static int cyttsp_set_operational_mode (struct cyttsp *ts) +{ + struct cyttsp_xydata xy_data; + int retval; + int tries; + u8 cmd = CY_OPERATE_MODE; + + retval = ttsp_write_block_data(ts, CY_REG_BASE, sizeof(cmd), &cmd); + + if (retval < 0) + return retval; + + /* wait for TTSP Device to complete switch to Operational mode */ + tries = 0; + do { + retval = ttsp_read_block_data(ts, CY_REG_BASE, + sizeof(xy_data), &(xy_data)); + } while (!((retval == 0) && + (xy_data.act_dist == CY_ACT_DIST_DFLT)) && + (tries++ < CY_DELAY_MAX));
Quoted 9 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c line 323
Quoted 6 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +6
-0+ + dev_dbg(ts->dev, "%s: check op ready tries=%d ret=%d dist=%02X\n", + __func__, tries, retval, xy_data.act_dist); + + return retval; +}So (xy_data.act_dist ==
CY_ACT_DIST_DFL) here is not an error?
Yes, it is. I'll add the check to report accordingly.
Quoted 19 lines
Quoted 19 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +19
-0+static int cyttsp_set_sysinfo_mode (struct cyttsp *ts) +{ + int retval; + int tries; + u8 cmd = CY_SYSINFO_MODE; + + memset(&(ts->sysinfo_data), 0, sizeof(struct cyttsp_sysinfo_data)); + + /* switch to sysinfo mode */ + retval = ttsp_write_block_data(ts, CY_REG_BASE, sizeof(cmd), &cmd); + if (retval < 0) + return retval; + + /* read sysinfo registers */ + tries = 0; + do { + msleep(CY_DELAY_DFLT); + retval = ttsp_read_block_data(ts, CY_REG_BASE, + sizeof(ts->sysinfo_data), &(ts->sysinfo_data));
Quoted 9 lines
Quoted 4 lines
+ } while (!((retval == 0) &&
+ !((ts->sysinfo_data.tts_verh == 0) &&
+ (ts->sysinfo_data.tts_verl== 0))) &&
+ (tries++ <CY_DELAY_MAX));Expands to (retval || !ts->sysinfo_data.tts_verh && !ts->sysinfo_data.tts_verl) && (tries++ <
CY_DELAY_MAX), which seems a bit simpler to me. Also,&ts->sysinfo_datacould be a pointer here.
Yes, it is simpler. Will change it.
Quoted 4 lines
Coding verh+verl as a 16-bit value?
Are the timeouted (tries >=
CY_DELAY_MAX) cases not errors here either?
Yes, we should report that also.
Quoted 12 lines
<snip>
Quoted 10 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +10
-0+static int cyttsp_soft_reset (struct cyttsp *ts) +{ + int retval; + u8 cmd = CY_SOFT_RESET_MODE; + long wait_jiffies = msecs_to_jiffies(CY_DELAY_DFLT * CY_DELAY_MAX); + /* wait for interrupt to set ready completion */ + INIT_COMPLETION(ts->bl_ready); + + retval = ttsp_write_block_data(ts, CY_REG_BASE, sizeof(cmd), &cmd); + if (retval < 0)
Quoted 9 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c line 403
Quoted 6 lines
+ return retval;
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +5
-0+ + retval = wait_for_completion_timeout(&ts->bl_ready, wait_jiffies); + + if (retval > 0) + retval = 0;Seems this one slipped.
What cleanup do you want me to do here? Remove the last retval? or there is some problem with the completion logic?
Quoted 6 lines
Quoted 6 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +6
-0+ + return retval; +} + +static int cyttsp_hndshk (struct cyttsp *ts,u8 hst_mode) +{
Quoted 9 lines
Quoted 6 lines
+ int retval;
+ u8 cmd;
+
+ cmd =hst_mode&CY_HNDSHK_BIT?
+hst_mode^CY_HNDSHK_BIT:
+hst_mode|CY_HNDSHK_BIT;Whoa, please redo this one correctly.
Ok, I just realized that what you meant:
cmd = hst_mode ^ CY_HNDSHK_BIT;
is logically equivalent. Sorry for the mess with binary operators.
Quoted 7 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c line 434
Quoted 6 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +6
-0+ + retval = ttsp_write_block_data(ts, CY_REG_BASE, + sizeof(cmd), (u8 *)&cmd); + + return retval; +}
Same here, will get rid of the retval with return ttsp_write_block_data().
Quoted 10 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c line 653
Quoted 7 lines
drivers/input/touchscreen/cyttsp/cyttsp_core.c new file +7
-0+int cyttsp_resume (void *handle) +{ + struct cyttsp *ts = handle; + int retval = 0; + struct cyttsp_xydata xydata; + + if (ts) {Neater if returning on (!ts) here instead.
Yes, will change that.
Quoted 22 lines
Quoted 22 lines
+ if (
ts->platform_data->use_sleep&& (ts->power_state!=
+ CY_ACTIVE_STATE)) {
+ if (ts->platform_data->wakeup) {
+ retval =ts->platform_data->wakeup();
+ if (retval < 0)
+ dev_dbg(ts->dev, "%s: Error, wakeup failed!\n",
+__func__);
+ } else {
+ dev_dbg(ts->dev, "%s: Error, wakeup not implemented "
+ "(check board file).\n",__func__);
+ retval =-ENOSYS;
+ }
+ if (!(retval < 0)) {
+ retval = ttsp_read_block_data(ts,CY_REG_BASE,
+ sizeof(xydata),
+ &xydata);
+ if (!(retval < 0) &&
+ !GET_HSTMODE(xydata.hst_mode))
+ts->power_state=CY_ACTIVE_STATE;
+ }
+ }
+ dev_dbg(ts->dev, "%s: Wake Up %s\n",__func__,
Quoted 9 lines
Review
Quoted 5 lines
+ (retval < 0) ? "FAIL" : "PASS");
+ }
+ return retval;(quoted diff) +2
-0+} +EXPORT_SYMBOL_GPL(cyttsp_resume);Thanks.
Henrik
I'll fix these issues and resend in the next days. Thank you very much for your time to review.
I'm new in kernel dev and it seems I'm still lacking "good taste" to code, but I hope I'll get there :-)
Best regards,
Signature · 3 lines
Javier Martínez Canillas (+34) 682 39 81 69 Barcelona, Spain