Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Ferruh Yigit and committed by
Dmitry Torokhov
9664877e b56ece9a

+112 -74
+1 -1
drivers/input/touchscreen/Makefile
··· 18 18 obj-$(CONFIG_TOUCHSCREEN_BU21013) += bu21013_ts.o 19 19 obj-$(CONFIG_TOUCHSCREEN_CY8CTMG110) += cy8ctmg110_ts.o 20 20 obj-$(CONFIG_TOUCHSCREEN_CYTTSP_CORE) += cyttsp_core.o 21 - obj-$(CONFIG_TOUCHSCREEN_CYTTSP_I2C) += cyttsp_i2c.o 21 + obj-$(CONFIG_TOUCHSCREEN_CYTTSP_I2C) += cyttsp_i2c.o cyttsp_i2c_common.o 22 22 obj-$(CONFIG_TOUCHSCREEN_CYTTSP_SPI) += cyttsp_spi.o 23 23 obj-$(CONFIG_TOUCHSCREEN_DA9034) += da9034-ts.o 24 24 obj-$(CONFIG_TOUCHSCREEN_DA9052) += da9052_tsi.o
+4 -2
drivers/input/touchscreen/cyttsp_core.c
··· 84 84 int tries; 85 85 86 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 89 if (!error) 89 90 return 0; 90 91 ··· 102 101 int tries; 103 102 104 103 for (tries = 0; tries < CY_NUM_RETRY; tries++) { 105 - error = ts->bus_ops->write(ts, command, length, buf); 104 + error = ts->bus_ops->write(ts->dev, ts->xfer_buf, command, 105 + length, buf); 106 106 if (!error) 107 107 return 0; 108 108
+8 -3
drivers/input/touchscreen/cyttsp_core.h
··· 112 112 113 113 struct cyttsp_bus_ops { 114 114 u16 bustype; 115 - int (*write)(struct cyttsp *ts, 116 - u8 addr, u8 length, const void *values); 117 - int (*read)(struct cyttsp *ts, u8 addr, u8 length, void *values); 115 + int (*write)(struct device *dev, u8 *xfer_buf, u8 addr, u8 length, 116 + const void *values); 117 + int (*read)(struct device *dev, u8 *xfer_buf, u8 addr, u8 length, 118 + void *values); 118 119 }; 119 120 120 121 enum cyttsp_state { ··· 145 144 struct device *dev, int irq, size_t xfer_buf_size); 146 145 void cyttsp_remove(struct cyttsp *ts); 147 146 147 + int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, u8 addr, 148 + u8 length, const void *values); 149 + int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf, u8 addr, 150 + u8 length, void *values); 148 151 extern const struct dev_pm_ops cyttsp_pm_ops; 149 152 150 153 #endif /* __CYTTSP_CORE_H__ */
+2 -48
drivers/input/touchscreen/cyttsp_i2c.c
··· 1 1 /* 2 - * Source for: 2 + * cyttsp_i2c.c 3 3 * Cypress TrueTouch(TM) Standard Product (TTSP) I2C touchscreen driver. 4 4 * For use with Cypress Txx3xx parts. 5 5 * Supported parts include: ··· 19 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 20 * GNU General Public License for more details. 21 21 * 22 - * You should have received a copy of the GNU General Public License along 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> 22 + * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com> 27 23 * 28 24 */ 29 25 ··· 29 33 #include <linux/input.h> 30 34 31 35 #define CY_I2C_DATA_SIZE 128 32 - 33 - static int cyttsp_i2c_read_block_data(struct cyttsp *ts, 34 - u8 addr, u8 length, void *values) 35 - { 36 - struct i2c_client *client = to_i2c_client(ts->dev); 37 - struct i2c_msg msgs[] = { 38 - { 39 - .addr = client->addr, 40 - .flags = 0, 41 - .len = 1, 42 - .buf = &addr, 43 - }, 44 - { 45 - .addr = client->addr, 46 - .flags = I2C_M_RD, 47 - .len = length, 48 - .buf = values, 49 - }, 50 - }; 51 - int retval; 52 - 53 - retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 54 - if (retval < 0) 55 - return retval; 56 - 57 - return retval != ARRAY_SIZE(msgs) ? -EIO : 0; 58 - } 59 - 60 - static int cyttsp_i2c_write_block_data(struct cyttsp *ts, 61 - u8 addr, u8 length, const void *values) 62 - { 63 - struct i2c_client *client = to_i2c_client(ts->dev); 64 - int retval; 65 - 66 - ts->xfer_buf[0] = addr; 67 - memcpy(&ts->xfer_buf[1], values, length); 68 - 69 - retval = i2c_master_send(client, ts->xfer_buf, length + 1); 70 - 71 - return retval < 0 ? retval : 0; 72 - } 73 36 74 37 static const struct cyttsp_bus_ops cyttsp_i2c_bus_ops = { 75 38 .bustype = BUS_I2C, ··· 53 98 return PTR_ERR(ts); 54 99 55 100 i2c_set_clientdata(client, ts); 56 - 57 101 return 0; 58 102 } 59 103
+79
drivers/input/touchscreen/cyttsp_i2c_common.c
··· 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 + 34 + int 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 + } 60 + EXPORT_SYMBOL_GPL(cyttsp_i2c_read_block_data); 61 + 62 + int 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 + } 75 + EXPORT_SYMBOL_GPL(cyttsp_i2c_write_block_data); 76 + 77 + 78 + MODULE_LICENSE("GPL"); 79 + MODULE_AUTHOR("Cypress");
+18 -20
drivers/input/touchscreen/cyttsp_spi.c
··· 8 8 * 9 9 * Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc. 10 10 * Copyright (C) 2012 Javier Martinez Canillas <javier@dowhile0.org> 11 + * Copyright (C) 2013 Cypress Semiconductor 11 12 * 12 13 * This program is free software; you can redistribute it and/or 13 14 * modify it under the terms of the GNU General Public License ··· 20 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 20 * GNU General Public License for more details. 22 21 * 23 - * You should have received a copy of the GNU General Public License along 24 - * with this program; if not, write to the Free Software Foundation, Inc., 25 - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 26 - * 27 - * Contact Cypress Semiconductor at www.cypress.com <kev@cypress.com> 22 + * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com> 28 23 * 29 24 */ 30 25 ··· 40 43 #define CY_SPI_DATA_BUF_SIZE (CY_SPI_CMD_BYTES + CY_SPI_DATA_SIZE) 41 44 #define CY_SPI_BITS_PER_WORD 8 42 45 43 - static int cyttsp_spi_xfer(struct cyttsp *ts, 46 + static int cyttsp_spi_xfer(struct device *dev, u8 *xfer_buf, 44 47 u8 op, u8 reg, u8 *buf, int length) 45 48 { 46 - struct spi_device *spi = to_spi_device(ts->dev); 49 + struct spi_device *spi = to_spi_device(dev); 47 50 struct spi_message msg; 48 51 struct spi_transfer xfer[2]; 49 - u8 *wr_buf = &ts->xfer_buf[0]; 50 - u8 *rd_buf = &ts->xfer_buf[CY_SPI_DATA_BUF_SIZE]; 52 + u8 *wr_buf = &xfer_buf[0]; 53 + u8 *rd_buf = &xfer_buf[CY_SPI_DATA_BUF_SIZE]; 51 54 int retval; 52 55 int i; 53 56 54 57 if (length > CY_SPI_DATA_SIZE) { 55 - dev_err(ts->dev, "%s: length %d is too big.\n", 58 + dev_err(dev, "%s: length %d is too big.\n", 56 59 __func__, length); 57 60 return -EINVAL; 58 61 } ··· 92 95 break; 93 96 94 97 default: 95 - dev_err(ts->dev, "%s: bad operation code=%d\n", __func__, op); 98 + dev_err(dev, "%s: bad operation code=%d\n", __func__, op); 96 99 return -EINVAL; 97 100 } 98 101 99 102 retval = spi_sync(spi, &msg); 100 103 if (retval < 0) { 101 - dev_dbg(ts->dev, "%s: spi_sync() error %d, len=%d, op=%d\n", 104 + dev_dbg(dev, "%s: spi_sync() error %d, len=%d, op=%d\n", 102 105 __func__, retval, xfer[1].len, op); 103 106 104 107 /* ··· 110 113 111 114 if (rd_buf[CY_SPI_SYNC_BYTE] != CY_SPI_SYNC_ACK1 || 112 115 rd_buf[CY_SPI_SYNC_BYTE + 1] != CY_SPI_SYNC_ACK2) { 113 - 114 - dev_dbg(ts->dev, "%s: operation %d failed\n", __func__, op); 116 + dev_dbg(dev, "%s: operation %d failed\n", __func__, op); 115 117 116 118 for (i = 0; i < CY_SPI_CMD_BYTES; i++) 117 - dev_dbg(ts->dev, "%s: test rd_buf[%d]:0x%02x\n", 119 + dev_dbg(dev, "%s: test rd_buf[%d]:0x%02x\n", 118 120 __func__, i, rd_buf[i]); 119 121 for (i = 0; i < length; i++) 120 - dev_dbg(ts->dev, "%s: test buf[%d]:0x%02x\n", 122 + dev_dbg(dev, "%s: test buf[%d]:0x%02x\n", 121 123 __func__, i, buf[i]); 122 124 123 125 return -EIO; ··· 125 129 return 0; 126 130 } 127 131 128 - static int cyttsp_spi_read_block_data(struct cyttsp *ts, 132 + static int cyttsp_spi_read_block_data(struct device *dev, u8 *xfer_buf, 129 133 u8 addr, u8 length, void *data) 130 134 { 131 - return cyttsp_spi_xfer(ts, CY_SPI_RD_OP, addr, data, length); 135 + return cyttsp_spi_xfer(dev, xfer_buf, CY_SPI_RD_OP, addr, data, 136 + length); 132 137 } 133 138 134 - static int cyttsp_spi_write_block_data(struct cyttsp *ts, 139 + static int cyttsp_spi_write_block_data(struct device *dev, u8 *xfer_buf, 135 140 u8 addr, u8 length, const void *data) 136 141 { 137 - return cyttsp_spi_xfer(ts, CY_SPI_WR_OP, addr, (void *)data, length); 142 + return cyttsp_spi_xfer(dev, xfer_buf, CY_SPI_WR_OP, addr, (void *)data, 143 + length); 138 144 } 139 145 140 146 static const struct cyttsp_bus_ops cyttsp_spi_bus_ops = {