0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include <linux/device.h>
0019 #include <linux/export.h>
0020 #include <linux/i2c.h>
0021 #include <linux/module.h>
0022 #include <linux/types.h>
0023
0024 #include "cyttsp4_core.h"
0025
0026 int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf,
0027 u16 addr, u8 length, void *values)
0028 {
0029 struct i2c_client *client = to_i2c_client(dev);
0030 u8 client_addr = client->addr | ((addr >> 8) & 0x1);
0031 u8 addr_lo = addr & 0xFF;
0032 struct i2c_msg msgs[] = {
0033 {
0034 .addr = client_addr,
0035 .flags = 0,
0036 .len = 1,
0037 .buf = &addr_lo,
0038 },
0039 {
0040 .addr = client_addr,
0041 .flags = I2C_M_RD,
0042 .len = length,
0043 .buf = values,
0044 },
0045 };
0046 int retval;
0047
0048 retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
0049 if (retval < 0)
0050 return retval;
0051
0052 return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
0053 }
0054 EXPORT_SYMBOL_GPL(cyttsp_i2c_read_block_data);
0055
0056 int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf,
0057 u16 addr, u8 length, const void *values)
0058 {
0059 struct i2c_client *client = to_i2c_client(dev);
0060 u8 client_addr = client->addr | ((addr >> 8) & 0x1);
0061 u8 addr_lo = addr & 0xFF;
0062 struct i2c_msg msgs[] = {
0063 {
0064 .addr = client_addr,
0065 .flags = 0,
0066 .len = length + 1,
0067 .buf = xfer_buf,
0068 },
0069 };
0070 int retval;
0071
0072 xfer_buf[0] = addr_lo;
0073 memcpy(&xfer_buf[1], values, length);
0074
0075 retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
0076 if (retval < 0)
0077 return retval;
0078
0079 return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
0080 }
0081 EXPORT_SYMBOL_GPL(cyttsp_i2c_write_block_data);
0082
0083
0084 MODULE_LICENSE("GPL");
0085 MODULE_AUTHOR("Cypress");