Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9664877e authored by Ferruh Yigit's avatar Ferruh Yigit Committed by Dmitry Torokhov
Browse files

Input: cyttsp - I2C driver split into two modules



Existing I2C code is for TrueTouch Gen3 devices

TrueTouch Gen4 device is using same protocol, will split driver into
two pieces to use common code with both drivers.

Read/Write functions parameter list modified, since shared code will
be used by two separate drivers and these drivers are not sharing same
structs, parameters updated to use common structures.

Signed-off-by: default avatarFerruh Yigit <fery@cypress.com>
Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: default avatarJavier Martinez Canillas <javier@dowhile0.org>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent b56ece9a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ obj-$(CONFIG_TOUCHSCREEN_AUO_PIXCIR) += auo-pixcir-ts.o
obj-$(CONFIG_TOUCHSCREEN_BU21013)	+= bu21013_ts.o
obj-$(CONFIG_TOUCHSCREEN_CY8CTMG110)	+= cy8ctmg110_ts.o
obj-$(CONFIG_TOUCHSCREEN_CYTTSP_CORE)	+= cyttsp_core.o
obj-$(CONFIG_TOUCHSCREEN_CYTTSP_I2C)	+= cyttsp_i2c.o
obj-$(CONFIG_TOUCHSCREEN_CYTTSP_I2C)	+= cyttsp_i2c.o cyttsp_i2c_common.o
obj-$(CONFIG_TOUCHSCREEN_CYTTSP_SPI)	+= cyttsp_spi.o
obj-$(CONFIG_TOUCHSCREEN_DA9034)	+= da9034-ts.o
obj-$(CONFIG_TOUCHSCREEN_DA9052)	+= da9052_tsi.o
+4 −2
Original line number Diff line number Diff line
@@ -84,7 +84,8 @@ static int ttsp_read_block_data(struct cyttsp *ts, u8 command,
	int tries;

	for (tries = 0; tries < CY_NUM_RETRY; tries++) {
		error = ts->bus_ops->read(ts, command, length, buf);
		error = ts->bus_ops->read(ts->dev, ts->xfer_buf, command,
				length, buf);
		if (!error)
			return 0;

@@ -101,7 +102,8 @@ static int ttsp_write_block_data(struct cyttsp *ts, u8 command,
	int tries;

	for (tries = 0; tries < CY_NUM_RETRY; tries++) {
		error = ts->bus_ops->write(ts, command, length, buf);
		error = ts->bus_ops->write(ts->dev, ts->xfer_buf, command,
				length, buf);
		if (!error)
			return 0;

+8 −3
Original line number Diff line number Diff line
@@ -112,9 +112,10 @@ struct cyttsp;

struct cyttsp_bus_ops {
	u16 bustype;
	int (*write)(struct cyttsp *ts,
		     u8 addr, u8 length, const void *values);
	int (*read)(struct cyttsp *ts, u8 addr, u8 length, void *values);
	int (*write)(struct device *dev, u8 *xfer_buf, u8 addr, u8 length,
			const void *values);
	int (*read)(struct device *dev, u8 *xfer_buf, u8 addr, u8 length,
			void *values);
};

enum cyttsp_state {
@@ -144,6 +145,10 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,
			    struct device *dev, int irq, size_t xfer_buf_size);
void cyttsp_remove(struct cyttsp *ts);

int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, u8 addr,
		u8 length, const void *values);
int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf, u8 addr,
		u8 length, void *values);
extern const struct dev_pm_ops cyttsp_pm_ops;

#endif /* __CYTTSP_CORE_H__ */
+2 −48
Original line number Diff line number Diff line
/*
 * Source for:
 * cyttsp_i2c.c
 * Cypress TrueTouch(TM) Standard Product (TTSP) I2C touchscreen driver.
 * For use with Cypress Txx3xx parts.
 * Supported parts include:
@@ -19,11 +19,7 @@
 * 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 <kev@cypress.com>
 * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com>
 *
 */

@@ -34,47 +30,6 @@

#define CY_I2C_DATA_SIZE	128

static int cyttsp_i2c_read_block_data(struct cyttsp *ts,
				      u8 addr, u8 length, void *values)
{
	struct i2c_client *client = to_i2c_client(ts->dev);
	struct i2c_msg msgs[] = {
		{
			.addr = client->addr,
			.flags = 0,
			.len = 1,
			.buf = &addr,
		},
		{
			.addr = client->addr,
			.flags = I2C_M_RD,
			.len = length,
			.buf = values,
		},
	};
	int retval;

	retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
	if (retval < 0)
		return retval;

	return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
}

static int cyttsp_i2c_write_block_data(struct cyttsp *ts,
				       u8 addr, u8 length, const void *values)
{
	struct i2c_client *client = to_i2c_client(ts->dev);
	int retval;

	ts->xfer_buf[0] = addr;
	memcpy(&ts->xfer_buf[1], values, length);

	retval = i2c_master_send(client, ts->xfer_buf, length + 1);

	return retval < 0 ? retval : 0;
}

static const struct cyttsp_bus_ops cyttsp_i2c_bus_ops = {
	.bustype	= BUS_I2C,
	.write		= cyttsp_i2c_write_block_data,
@@ -98,7 +53,6 @@ static int cyttsp_i2c_probe(struct i2c_client *client,
		return PTR_ERR(ts);

	i2c_set_clientdata(client, ts);

	return 0;
}

+79 −0
Original line number Diff line number Diff line
/*
 * cyttsp_i2c_common.c
 * Cypress TrueTouch(TM) Standard Product (TTSP) I2C touchscreen driver.
 * For use with Cypress Txx3xx and Txx4xx parts.
 * Supported parts include:
 * CY8CTST341
 * CY8CTMA340
 * TMA4XX
 * TMA1036
 *
 * Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc.
 * Copyright (C) 2012 Javier Martinez Canillas <javier@dowhile0.org>
 *
 * 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.
 *
 * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com>
 *
 */

#include <linux/device.h>
#include <linux/export.h>
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/types.h>

int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf,
				      u8 addr, u8 length, void *values)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct i2c_msg msgs[] = {
		{
			.addr = client->addr,
			.flags = 0,
			.len = 1,
			.buf = &addr,
		},
		{
			.addr = client->addr,
			.flags = I2C_M_RD,
			.len = length,
			.buf = values,
		},
	};
	int retval;

	retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
	if (retval < 0)
		return retval;

	return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
}
EXPORT_SYMBOL_GPL(cyttsp_i2c_read_block_data);

int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf,
				       u8 addr, u8 length, const void *values)
{
	struct i2c_client *client = to_i2c_client(dev);
	int retval;

	xfer_buf[0] = addr;
	memcpy(&xfer_buf[1], values, length);

	retval = i2c_master_send(client, xfer_buf, length + 1);

	return retval < 0 ? retval : 0;
}
EXPORT_SYMBOL_GPL(cyttsp_i2c_write_block_data);


MODULE_LICENSE("GPL");
MODULE_AUTHOR("Cypress");
Loading