Skip to content

Commit 62f548d

Browse files
Ferruh Yigitdtor
authored andcommitted
Input: cyttsp4 - use 16bit address for I2C/SPI communication
In TSG4, register map is 512bytes long and to access all of it, one bit from address byte is used (which bit to use differs for I2C and SPI); Since common code used for TSG3 and TSG4 for I2C, this parameter wrongly used as u8. TSG3 does not access beyond 255 bytes but TSG4 may. Tested-on:TMA3XX DVB && TMA4XX DVB Signed-off-by: Ferruh Yigit <[email protected]> Acked-by: Javier Martinez Canillas <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent 57961e3 commit 62f548d

File tree

5 files changed

+44
-32
lines changed

5 files changed

+44
-32
lines changed

drivers/input/touchscreen/cyttsp4_core.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,9 @@ struct cyttsp4 {
369369

370370
struct cyttsp4_bus_ops {
371371
u16 bustype;
372-
int (*write)(struct device *dev, u8 *xfer_buf, u8 addr, u8 length,
372+
int (*write)(struct device *dev, u8 *xfer_buf, u16 addr, u8 length,
373373
const void *values);
374-
int (*read)(struct device *dev, u8 *xfer_buf, u8 addr, u8 length,
374+
int (*read)(struct device *dev, u8 *xfer_buf, u16 addr, u8 length,
375375
void *values);
376376
};
377377

@@ -448,13 +448,13 @@ enum cyttsp4_event_id {
448448
/* y-axis, 0:origin is on top side of panel, 1: bottom */
449449
#define CY_PCFG_ORIGIN_Y_MASK 0x80
450450

451-
static inline int cyttsp4_adap_read(struct cyttsp4 *ts, u8 addr, int size,
451+
static inline int cyttsp4_adap_read(struct cyttsp4 *ts, u16 addr, int size,
452452
void *buf)
453453
{
454454
return ts->bus_ops->read(ts->dev, ts->xfer_buf, addr, size, buf);
455455
}
456456

457-
static inline int cyttsp4_adap_write(struct cyttsp4 *ts, u8 addr, int size,
457+
static inline int cyttsp4_adap_write(struct cyttsp4 *ts, u16 addr, int size,
458458
const void *buf)
459459
{
460460
return ts->bus_ops->write(ts->dev, ts->xfer_buf, addr, size, buf);
@@ -463,9 +463,9 @@ static inline int cyttsp4_adap_write(struct cyttsp4 *ts, u8 addr, int size,
463463
extern struct cyttsp4 *cyttsp4_probe(const struct cyttsp4_bus_ops *ops,
464464
struct device *dev, u16 irq, size_t xfer_buf_size);
465465
extern int cyttsp4_remove(struct cyttsp4 *ts);
466-
int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, u8 addr,
466+
int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, u16 addr,
467467
u8 length, const void *values);
468-
int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf, u8 addr,
468+
int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf, u16 addr,
469469
u8 length, void *values);
470470
extern const struct dev_pm_ops cyttsp4_pm_ops;
471471

drivers/input/touchscreen/cyttsp4_spi.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#define CY_SPI_DATA_BUF_SIZE (CY_SPI_CMD_BYTES + CY_SPI_DATA_SIZE)
4545

4646
static int cyttsp_spi_xfer(struct device *dev, u8 *xfer_buf,
47-
u8 op, u8 reg, u8 *buf, int length)
47+
u8 op, u16 reg, u8 *buf, int length)
4848
{
4949
struct spi_device *spi = to_spi_device(dev);
5050
struct spi_message msg;
@@ -63,14 +63,12 @@ static int cyttsp_spi_xfer(struct device *dev, u8 *xfer_buf,
6363
memset(wr_buf, 0, CY_SPI_DATA_BUF_SIZE);
6464
memset(rd_buf, 0, CY_SPI_CMD_BYTES);
6565

66-
if (reg > 255)
67-
wr_buf[0] = op + CY_SPI_A8_BIT;
68-
else
69-
wr_buf[0] = op;
70-
if (op == CY_SPI_WR_OP)
71-
wr_buf[1] = reg % 256;
72-
if (op == CY_SPI_WR_OP && length > 0)
73-
memcpy(wr_buf + CY_SPI_CMD_BYTES, buf, length);
66+
wr_buf[0] = op + (((reg >> 8) & 0x1) ? CY_SPI_A8_BIT : 0);
67+
if (op == CY_SPI_WR_OP) {
68+
wr_buf[1] = reg & 0xFF;
69+
if (length > 0)
70+
memcpy(wr_buf + CY_SPI_CMD_BYTES, buf, length);
71+
}
7472

7573
memset(xfer, 0, sizeof(xfer));
7674
spi_message_init(&msg);
@@ -130,7 +128,7 @@ static int cyttsp_spi_xfer(struct device *dev, u8 *xfer_buf,
130128
}
131129

132130
static int cyttsp_spi_read_block_data(struct device *dev, u8 *xfer_buf,
133-
u8 addr, u8 length, void *data)
131+
u16 addr, u8 length, void *data)
134132
{
135133
int rc;
136134

@@ -143,7 +141,7 @@ static int cyttsp_spi_read_block_data(struct device *dev, u8 *xfer_buf,
143141
}
144142

145143
static int cyttsp_spi_write_block_data(struct device *dev, u8 *xfer_buf,
146-
u8 addr, u8 length, const void *data)
144+
u16 addr, u8 length, const void *data)
147145
{
148146
return cyttsp_spi_xfer(dev, xfer_buf, CY_SPI_WR_OP, addr, (void *)data,
149147
length);

drivers/input/touchscreen/cyttsp_core.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ struct cyttsp;
112112

113113
struct cyttsp_bus_ops {
114114
u16 bustype;
115-
int (*write)(struct device *dev, u8 *xfer_buf, u8 addr, u8 length,
115+
int (*write)(struct device *dev, u8 *xfer_buf, u16 addr, u8 length,
116116
const void *values);
117-
int (*read)(struct device *dev, u8 *xfer_buf, u8 addr, u8 length,
117+
int (*read)(struct device *dev, u8 *xfer_buf, u16 addr, u8 length,
118118
void *values);
119119
};
120120

@@ -145,9 +145,9 @@ struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,
145145
struct device *dev, int irq, size_t xfer_buf_size);
146146
void cyttsp_remove(struct cyttsp *ts);
147147

148-
int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, u8 addr,
148+
int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, u16 addr,
149149
u8 length, const void *values);
150-
int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf, u8 addr,
150+
int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf, u16 addr,
151151
u8 length, void *values);
152152
extern const struct dev_pm_ops cyttsp_pm_ops;
153153

drivers/input/touchscreen/cyttsp_i2c_common.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,20 @@
3232
#include <linux/types.h>
3333

3434
int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf,
35-
u8 addr, u8 length, void *values)
35+
u16 addr, u8 length, void *values)
3636
{
3737
struct i2c_client *client = to_i2c_client(dev);
38+
u8 client_addr = client->addr | ((addr >> 8) & 0x1);
39+
u8 addr_lo = addr & 0xFF;
3840
struct i2c_msg msgs[] = {
3941
{
40-
.addr = client->addr,
42+
.addr = client_addr,
4143
.flags = 0,
4244
.len = 1,
43-
.buf = &addr,
45+
.buf = &addr_lo,
4446
},
4547
{
46-
.addr = client->addr,
48+
.addr = client_addr,
4749
.flags = I2C_M_RD,
4850
.len = length,
4951
.buf = values,
@@ -60,17 +62,29 @@ int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf,
6062
EXPORT_SYMBOL_GPL(cyttsp_i2c_read_block_data);
6163

6264
int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf,
63-
u8 addr, u8 length, const void *values)
65+
u16 addr, u8 length, const void *values)
6466
{
6567
struct i2c_client *client = to_i2c_client(dev);
68+
u8 client_addr = client->addr | ((addr >> 8) & 0x1);
69+
u8 addr_lo = addr & 0xFF;
70+
struct i2c_msg msgs[] = {
71+
{
72+
.addr = client_addr,
73+
.flags = 0,
74+
.len = length + 1,
75+
.buf = xfer_buf,
76+
},
77+
};
6678
int retval;
6779

68-
xfer_buf[0] = addr;
80+
xfer_buf[0] = addr_lo;
6981
memcpy(&xfer_buf[1], values, length);
7082

71-
retval = i2c_master_send(client, xfer_buf, length + 1);
83+
retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
84+
if (retval < 0)
85+
return retval;
7286

73-
return retval < 0 ? retval : 0;
87+
return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
7488
}
7589
EXPORT_SYMBOL_GPL(cyttsp_i2c_write_block_data);
7690

drivers/input/touchscreen/cyttsp_spi.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#define CY_SPI_BITS_PER_WORD 8
4242

4343
static int cyttsp_spi_xfer(struct device *dev, u8 *xfer_buf,
44-
u8 op, u8 reg, u8 *buf, int length)
44+
u8 op, u16 reg, u8 *buf, int length)
4545
{
4646
struct spi_device *spi = to_spi_device(dev);
4747
struct spi_message msg;
@@ -126,14 +126,14 @@ static int cyttsp_spi_xfer(struct device *dev, u8 *xfer_buf,
126126
}
127127

128128
static int cyttsp_spi_read_block_data(struct device *dev, u8 *xfer_buf,
129-
u8 addr, u8 length, void *data)
129+
u16 addr, u8 length, void *data)
130130
{
131131
return cyttsp_spi_xfer(dev, xfer_buf, CY_SPI_RD_OP, addr, data,
132132
length);
133133
}
134134

135135
static int cyttsp_spi_write_block_data(struct device *dev, u8 *xfer_buf,
136-
u8 addr, u8 length, const void *data)
136+
u16 addr, u8 length, const void *data)
137137
{
138138
return cyttsp_spi_xfer(dev, xfer_buf, CY_SPI_WR_OP, addr, (void *)data,
139139
length);

0 commit comments

Comments
 (0)