1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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#include "cyttsp4_core.h"
35
36int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf,
37 u16 addr, u8 length, void *values)
38{
39 struct i2c_client *client = to_i2c_client(dev);
40 u8 client_addr = client->addr | ((addr >> 8) & 0x1);
41 u8 addr_lo = addr & 0xFF;
42 struct i2c_msg msgs[] = {
43 {
44 .addr = client_addr,
45 .flags = 0,
46 .len = 1,
47 .buf = &addr_lo,
48 },
49 {
50 .addr = client_addr,
51 .flags = I2C_M_RD,
52 .len = length,
53 .buf = values,
54 },
55 };
56 int retval;
57
58 retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
59 if (retval < 0)
60 return retval;
61
62 return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
63}
64EXPORT_SYMBOL_GPL(cyttsp_i2c_read_block_data);
65
66int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf,
67 u16 addr, u8 length, const void *values)
68{
69 struct i2c_client *client = to_i2c_client(dev);
70 u8 client_addr = client->addr | ((addr >> 8) & 0x1);
71 u8 addr_lo = addr & 0xFF;
72 struct i2c_msg msgs[] = {
73 {
74 .addr = client_addr,
75 .flags = 0,
76 .len = length + 1,
77 .buf = xfer_buf,
78 },
79 };
80 int retval;
81
82 xfer_buf[0] = addr_lo;
83 memcpy(&xfer_buf[1], values, length);
84
85 retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
86 if (retval < 0)
87 return retval;
88
89 return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
90}
91EXPORT_SYMBOL_GPL(cyttsp_i2c_write_block_data);
92
93
94MODULE_LICENSE("GPL");
95MODULE_AUTHOR("Cypress");
96