aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/touchscreen
diff options
context:
space:
mode:
authorFerruh Yigit <fery@cypress.com>2013-06-30 21:46:56 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2013-07-01 00:24:16 -0400
commit9664877ed8956b81feb3bd6b3b2621b5fcdb624f (patch)
tree47686dcd90262e9badd8dcdff641520e68389833 /drivers/input/touchscreen
parentb56ece9a3ac3c9708b8f1cebf4ba24c258d40e52 (diff)
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: Ferruh Yigit <fery@cypress.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Acked-by: Javier Martinez Canillas <javier@dowhile0.org> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/touchscreen')
-rw-r--r--drivers/input/touchscreen/Makefile2
-rw-r--r--drivers/input/touchscreen/cyttsp_core.c6
-rw-r--r--drivers/input/touchscreen/cyttsp_core.h11
-rw-r--r--drivers/input/touchscreen/cyttsp_i2c.c50
-rw-r--r--drivers/input/touchscreen/cyttsp_i2c_common.c79
-rw-r--r--drivers/input/touchscreen/cyttsp_spi.c38
6 files changed, 112 insertions, 74 deletions
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index 6bfbeab67c9f..2b378b12ee6b 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -18,7 +18,7 @@ obj-$(CONFIG_TOUCHSCREEN_AUO_PIXCIR) += auo-pixcir-ts.o
18obj-$(CONFIG_TOUCHSCREEN_BU21013) += bu21013_ts.o 18obj-$(CONFIG_TOUCHSCREEN_BU21013) += bu21013_ts.o
19obj-$(CONFIG_TOUCHSCREEN_CY8CTMG110) += cy8ctmg110_ts.o 19obj-$(CONFIG_TOUCHSCREEN_CY8CTMG110) += cy8ctmg110_ts.o
20obj-$(CONFIG_TOUCHSCREEN_CYTTSP_CORE) += cyttsp_core.o 20obj-$(CONFIG_TOUCHSCREEN_CYTTSP_CORE) += cyttsp_core.o
21obj-$(CONFIG_TOUCHSCREEN_CYTTSP_I2C) += cyttsp_i2c.o 21obj-$(CONFIG_TOUCHSCREEN_CYTTSP_I2C) += cyttsp_i2c.o cyttsp_i2c_common.o
22obj-$(CONFIG_TOUCHSCREEN_CYTTSP_SPI) += cyttsp_spi.o 22obj-$(CONFIG_TOUCHSCREEN_CYTTSP_SPI) += cyttsp_spi.o
23obj-$(CONFIG_TOUCHSCREEN_DA9034) += da9034-ts.o 23obj-$(CONFIG_TOUCHSCREEN_DA9034) += da9034-ts.o
24obj-$(CONFIG_TOUCHSCREEN_DA9052) += da9052_tsi.o 24obj-$(CONFIG_TOUCHSCREEN_DA9052) += da9052_tsi.o
diff --git a/drivers/input/touchscreen/cyttsp_core.c b/drivers/input/touchscreen/cyttsp_core.c
index 8e60437ac85b..4824fa343897 100644
--- a/drivers/input/touchscreen/cyttsp_core.c
+++ b/drivers/input/touchscreen/cyttsp_core.c
@@ -84,7 +84,8 @@ static int ttsp_read_block_data(struct cyttsp *ts, u8 command,
84 int tries; 84 int tries;
85 85
86 for (tries = 0; tries < CY_NUM_RETRY; tries++) { 86 for (tries = 0; tries < CY_NUM_RETRY; tries++) {
87 error = ts->bus_ops->read(ts, command, length, buf); 87 error = ts->bus_ops->read(ts->dev, ts->xfer_buf, command,
88 length, buf);
88 if (!error) 89 if (!error)
89 return 0; 90 return 0;
90 91
@@ -101,7 +102,8 @@ static int ttsp_write_block_data(struct cyttsp *ts, u8 command,
101 int tries; 102 int tries;
102 103
103 for (tries = 0; tries < CY_NUM_RETRY; tries++) { 104 for (tries = 0; tries < CY_NUM_RETRY; tries++) {
104 error = ts->bus_ops->write(ts, command, length, buf); 105 error = ts->bus_ops->write(ts->dev, ts->xfer_buf, command,
106 length, buf);
105 if (!error) 107 if (!error)
106 return 0; 108 return 0;
107 109
diff --git a/drivers/input/touchscreen/cyttsp_core.h b/drivers/input/touchscreen/cyttsp_core.h
index 1aa3c6967e70..d0c9e488b05d 100644
--- a/drivers/input/touchscreen/cyttsp_core.h
+++ b/drivers/input/touchscreen/cyttsp_core.h
@@ -112,9 +112,10 @@ struct cyttsp;
112 112
113struct cyttsp_bus_ops { 113struct cyttsp_bus_ops {
114 u16 bustype; 114 u16 bustype;
115 int (*write)(struct cyttsp *ts, 115 int (*write)(struct device *dev, u8 *xfer_buf, u8 addr, u8 length,
116 u8 addr, u8 length, const void *values); 116 const void *values);
117 int (*read)(struct cyttsp *ts, u8 addr, u8 length, void *values); 117 int (*read)(struct device *dev, u8 *xfer_buf, u8 addr, u8 length,
118 void *values);
118}; 119};
119 120
120enum cyttsp_state { 121enum cyttsp_state {
@@ -144,6 +145,10 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,
144 struct device *dev, int irq, size_t xfer_buf_size); 145 struct device *dev, int irq, size_t xfer_buf_size);
145void cyttsp_remove(struct cyttsp *ts); 146void cyttsp_remove(struct cyttsp *ts);
146 147
148int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, u8 addr,
149 u8 length, const void *values);
150int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf, u8 addr,
151 u8 length, void *values);
147extern const struct dev_pm_ops cyttsp_pm_ops; 152extern const struct dev_pm_ops cyttsp_pm_ops;
148 153
149#endif /* __CYTTSP_CORE_H__ */ 154#endif /* __CYTTSP_CORE_H__ */
diff --git a/drivers/input/touchscreen/cyttsp_i2c.c b/drivers/input/touchscreen/cyttsp_i2c.c
index 4dbdf44b8fc5..63104a86a9bd 100644
--- a/drivers/input/touchscreen/cyttsp_i2c.c
+++ b/drivers/input/touchscreen/cyttsp_i2c.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Source for: 2 * cyttsp_i2c.c
3 * Cypress TrueTouch(TM) Standard Product (TTSP) I2C touchscreen driver. 3 * Cypress TrueTouch(TM) Standard Product (TTSP) I2C touchscreen driver.
4 * For use with Cypress Txx3xx parts. 4 * For use with Cypress Txx3xx parts.
5 * Supported parts include: 5 * Supported parts include:
@@ -19,11 +19,7 @@
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details. 20 * GNU General Public License for more details.
21 * 21 *
22 * You should have received a copy of the GNU General Public License along 22 * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com>
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 *
26 * Contact Cypress Semiconductor at www.cypress.com <kev@cypress.com>
27 * 23 *
28 */ 24 */
29 25
@@ -34,47 +30,6 @@
34 30
35#define CY_I2C_DATA_SIZE 128 31#define CY_I2C_DATA_SIZE 128
36 32
37static int cyttsp_i2c_read_block_data(struct cyttsp *ts,
38 u8 addr, u8 length, void *values)
39{
40 struct i2c_client *client = to_i2c_client(ts->dev);
41 struct i2c_msg msgs[] = {
42 {
43 .addr = client->addr,
44 .flags = 0,
45 .len = 1,
46 .buf = &addr,
47 },
48 {
49 .addr = client->addr,
50 .flags = I2C_M_RD,
51 .len = length,
52 .buf = values,
53 },
54 };
55 int retval;
56
57 retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
58 if (retval < 0)
59 return retval;
60
61 return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
62}
63
64static int cyttsp_i2c_write_block_data(struct cyttsp *ts,
65 u8 addr, u8 length, const void *values)
66{
67 struct i2c_client *client = to_i2c_client(ts->dev);
68 int retval;
69
70 ts->xfer_buf[0] = addr;
71 memcpy(&ts->xfer_buf[1], values, length);
72
73 retval = i2c_master_send(client, ts->xfer_buf, length + 1);
74
75 return retval < 0 ? retval : 0;
76}
77
78static const struct cyttsp_bus_ops cyttsp_i2c_bus_ops = { 33static const struct cyttsp_bus_ops cyttsp_i2c_bus_ops = {
79 .bustype = BUS_I2C, 34 .bustype = BUS_I2C,
80 .write = cyttsp_i2c_write_block_data, 35 .write = cyttsp_i2c_write_block_data,
@@ -98,7 +53,6 @@ static int cyttsp_i2c_probe(struct i2c_client *client,
98 return PTR_ERR(ts); 53 return PTR_ERR(ts);
99 54
100 i2c_set_clientdata(client, ts); 55 i2c_set_clientdata(client, ts);
101
102 return 0; 56 return 0;
103} 57}
104 58
diff --git a/drivers/input/touchscreen/cyttsp_i2c_common.c b/drivers/input/touchscreen/cyttsp_i2c_common.c
new file mode 100644
index 000000000000..07c553fbcef2
--- /dev/null
+++ b/drivers/input/touchscreen/cyttsp_i2c_common.c
@@ -0,0 +1,79 @@
1/*
2 * cyttsp_i2c_common.c
3 * Cypress TrueTouch(TM) Standard Product (TTSP) I2C touchscreen driver.
4 * For use with Cypress Txx3xx and Txx4xx parts.
5 * Supported parts include:
6 * CY8CTST341
7 * CY8CTMA340
8 * TMA4XX
9 * TMA1036
10 *
11 * Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc.
12 * Copyright (C) 2012 Javier Martinez Canillas <javier@dowhile0.org>
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * version 2, and only version 2, as published by the
17 * Free Software Foundation.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com>
25 *
26 */
27
28#include <linux/device.h>
29#include <linux/export.h>
30#include <linux/i2c.h>
31#include <linux/module.h>
32#include <linux/types.h>
33
34int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf,
35 u8 addr, u8 length, void *values)
36{
37 struct i2c_client *client = to_i2c_client(dev);
38 struct i2c_msg msgs[] = {
39 {
40 .addr = client->addr,
41 .flags = 0,
42 .len = 1,
43 .buf = &addr,
44 },
45 {
46 .addr = client->addr,
47 .flags = I2C_M_RD,
48 .len = length,
49 .buf = values,
50 },
51 };
52 int retval;
53
54 retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
55 if (retval < 0)
56 return retval;
57
58 return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
59}
60EXPORT_SYMBOL_GPL(cyttsp_i2c_read_block_data);
61
62int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf,
63 u8 addr, u8 length, const void *values)
64{
65 struct i2c_client *client = to_i2c_client(dev);
66 int retval;
67
68 xfer_buf[0] = addr;
69 memcpy(&xfer_buf[1], values, length);
70
71 retval = i2c_master_send(client, xfer_buf, length + 1);
72
73 return retval < 0 ? retval : 0;
74}
75EXPORT_SYMBOL_GPL(cyttsp_i2c_write_block_data);
76
77
78MODULE_LICENSE("GPL");
79MODULE_AUTHOR("Cypress");
diff --git a/drivers/input/touchscreen/cyttsp_spi.c b/drivers/input/touchscreen/cyttsp_spi.c
index 861b7f77605b..1df625337b84 100644
--- a/drivers/input/touchscreen/cyttsp_spi.c
+++ b/drivers/input/touchscreen/cyttsp_spi.c
@@ -8,6 +8,7 @@
8 * 8 *
9 * Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc. 9 * Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc.
10 * Copyright (C) 2012 Javier Martinez Canillas <javier@dowhile0.org> 10 * Copyright (C) 2012 Javier Martinez Canillas <javier@dowhile0.org>
11 * Copyright (C) 2013 Cypress Semiconductor
11 * 12 *
12 * This program is free software; you can redistribute it and/or 13 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License 14 * modify it under the terms of the GNU General Public License
@@ -19,11 +20,7 @@
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details. 21 * GNU General Public License for more details.
21 * 22 *
22 * You should have received a copy of the GNU General Public License along 23 * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com>
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 *
26 * Contact Cypress Semiconductor at www.cypress.com <kev@cypress.com>
27 * 24 *
28 */ 25 */
29 26
@@ -43,19 +40,19 @@
43#define CY_SPI_DATA_BUF_SIZE (CY_SPI_CMD_BYTES + CY_SPI_DATA_SIZE) 40#define CY_SPI_DATA_BUF_SIZE (CY_SPI_CMD_BYTES + CY_SPI_DATA_SIZE)
44#define CY_SPI_BITS_PER_WORD 8 41#define CY_SPI_BITS_PER_WORD 8
45 42
46static int cyttsp_spi_xfer(struct cyttsp *ts, 43static int cyttsp_spi_xfer(struct device *dev, u8 *xfer_buf,
47 u8 op, u8 reg, u8 *buf, int length) 44 u8 op, u8 reg, u8 *buf, int length)
48{ 45{
49 struct spi_device *spi = to_spi_device(ts->dev); 46 struct spi_device *spi = to_spi_device(dev);
50 struct spi_message msg; 47 struct spi_message msg;
51 struct spi_transfer xfer[2]; 48 struct spi_transfer xfer[2];
52 u8 *wr_buf = &ts->xfer_buf[0]; 49 u8 *wr_buf = &xfer_buf[0];
53 u8 *rd_buf = &ts->xfer_buf[CY_SPI_DATA_BUF_SIZE]; 50 u8 *rd_buf = &xfer_buf[CY_SPI_DATA_BUF_SIZE];
54 int retval; 51 int retval;
55 int i; 52 int i;
56 53
57 if (length > CY_SPI_DATA_SIZE) { 54 if (length > CY_SPI_DATA_SIZE) {
58 dev_err(ts->dev, "%s: length %d is too big.\n", 55 dev_err(dev, "%s: length %d is too big.\n",
59 __func__, length); 56 __func__, length);
60 return -EINVAL; 57 return -EINVAL;
61 } 58 }
@@ -95,13 +92,13 @@ static int cyttsp_spi_xfer(struct cyttsp *ts,
95 break; 92 break;
96 93
97 default: 94 default:
98 dev_err(ts->dev, "%s: bad operation code=%d\n", __func__, op); 95 dev_err(dev, "%s: bad operation code=%d\n", __func__, op);
99 return -EINVAL; 96 return -EINVAL;
100 } 97 }
101 98
102 retval = spi_sync(spi, &msg); 99 retval = spi_sync(spi, &msg);
103 if (retval < 0) { 100 if (retval < 0) {
104 dev_dbg(ts->dev, "%s: spi_sync() error %d, len=%d, op=%d\n", 101 dev_dbg(dev, "%s: spi_sync() error %d, len=%d, op=%d\n",
105 __func__, retval, xfer[1].len, op); 102 __func__, retval, xfer[1].len, op);
106 103
107 /* 104 /*
@@ -113,14 +110,13 @@ static int cyttsp_spi_xfer(struct cyttsp *ts,
113 110
114 if (rd_buf[CY_SPI_SYNC_BYTE] != CY_SPI_SYNC_ACK1 || 111 if (rd_buf[CY_SPI_SYNC_BYTE] != CY_SPI_SYNC_ACK1 ||
115 rd_buf[CY_SPI_SYNC_BYTE + 1] != CY_SPI_SYNC_ACK2) { 112 rd_buf[CY_SPI_SYNC_BYTE + 1] != CY_SPI_SYNC_ACK2) {
116 113 dev_dbg(dev, "%s: operation %d failed\n", __func__, op);
117 dev_dbg(ts->dev, "%s: operation %d failed\n", __func__, op);
118 114
119 for (i = 0; i < CY_SPI_CMD_BYTES; i++) 115 for (i = 0; i < CY_SPI_CMD_BYTES; i++)
120 dev_dbg(ts->dev, "%s: test rd_buf[%d]:0x%02x\n", 116 dev_dbg(dev, "%s: test rd_buf[%d]:0x%02x\n",
121 __func__, i, rd_buf[i]); 117 __func__, i, rd_buf[i]);
122 for (i = 0; i < length; i++) 118 for (i = 0; i < length; i++)
123 dev_dbg(ts->dev, "%s: test buf[%d]:0x%02x\n", 119 dev_dbg(dev, "%s: test buf[%d]:0x%02x\n",
124 __func__, i, buf[i]); 120 __func__, i, buf[i]);
125 121
126 return -EIO; 122 return -EIO;
@@ -129,16 +125,18 @@ static int cyttsp_spi_xfer(struct cyttsp *ts,
129 return 0; 125 return 0;
130} 126}
131 127
132static int cyttsp_spi_read_block_data(struct cyttsp *ts, 128static int cyttsp_spi_read_block_data(struct device *dev, u8 *xfer_buf,
133 u8 addr, u8 length, void *data) 129 u8 addr, u8 length, void *data)
134{ 130{
135 return cyttsp_spi_xfer(ts, CY_SPI_RD_OP, addr, data, length); 131 return cyttsp_spi_xfer(dev, xfer_buf, CY_SPI_RD_OP, addr, data,
132 length);
136} 133}
137 134
138static int cyttsp_spi_write_block_data(struct cyttsp *ts, 135static int cyttsp_spi_write_block_data(struct device *dev, u8 *xfer_buf,
139 u8 addr, u8 length, const void *data) 136 u8 addr, u8 length, const void *data)
140{ 137{
141 return cyttsp_spi_xfer(ts, CY_SPI_WR_OP, addr, (void *)data, length); 138 return cyttsp_spi_xfer(dev, xfer_buf, CY_SPI_WR_OP, addr, (void *)data,
139 length);
142} 140}
143 141
144static const struct cyttsp_bus_ops cyttsp_spi_bus_ops = { 142static const struct cyttsp_bus_ops cyttsp_spi_bus_ops = {