uapi/if_ether.h: move __UAPI_DEF_ETHHDR libc define
[linux/fpc-iii.git] / drivers / input / touchscreen / cyttsp_i2c_common.c
blobccefa56ca21216f7f76e8596771b80cc6fd0c5ce
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
11 * Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc.
12 * Copyright (C) 2012 Javier Martinez Canillas <javier@dowhile0.org>
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.
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.
24 * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com>
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>
34 #include "cyttsp4_core.h"
36 int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf,
37 u16 addr, u8 length, void *values)
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[] = {
44 .addr = client_addr,
45 .flags = 0,
46 .len = 1,
47 .buf = &addr_lo,
50 .addr = client_addr,
51 .flags = I2C_M_RD,
52 .len = length,
53 .buf = values,
56 int retval;
58 retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
59 if (retval < 0)
60 return retval;
62 return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
64 EXPORT_SYMBOL_GPL(cyttsp_i2c_read_block_data);
66 int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf,
67 u16 addr, u8 length, const void *values)
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[] = {
74 .addr = client_addr,
75 .flags = 0,
76 .len = length + 1,
77 .buf = xfer_buf,
80 int retval;
82 xfer_buf[0] = addr_lo;
83 memcpy(&xfer_buf[1], values, length);
85 retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
86 if (retval < 0)
87 return retval;
89 return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
91 EXPORT_SYMBOL_GPL(cyttsp_i2c_write_block_data);
94 MODULE_LICENSE("GPL");
95 MODULE_AUTHOR("Cypress");