blob: 1d7b6f154168cc213e75ea64ee4f973782d0a108 [file] [log] [blame]
Ferruh Yigit96648772013-06-30 18:46:56 -07001/*
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
34int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf,
Ferruh Yigit62f548d2013-07-04 14:02:57 -070035 u16 addr, u8 length, void *values)
Ferruh Yigit96648772013-06-30 18:46:56 -070036{
37 struct i2c_client *client = to_i2c_client(dev);
Ferruh Yigit62f548d2013-07-04 14:02:57 -070038 u8 client_addr = client->addr | ((addr >> 8) & 0x1);
39 u8 addr_lo = addr & 0xFF;
Ferruh Yigit96648772013-06-30 18:46:56 -070040 struct i2c_msg msgs[] = {
41 {
Ferruh Yigit62f548d2013-07-04 14:02:57 -070042 .addr = client_addr,
Ferruh Yigit96648772013-06-30 18:46:56 -070043 .flags = 0,
44 .len = 1,
Ferruh Yigit62f548d2013-07-04 14:02:57 -070045 .buf = &addr_lo,
Ferruh Yigit96648772013-06-30 18:46:56 -070046 },
47 {
Ferruh Yigit62f548d2013-07-04 14:02:57 -070048 .addr = client_addr,
Ferruh Yigit96648772013-06-30 18:46:56 -070049 .flags = I2C_M_RD,
50 .len = length,
51 .buf = values,
52 },
53 };
54 int retval;
55
56 retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
57 if (retval < 0)
58 return retval;
59
60 return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
61}
62EXPORT_SYMBOL_GPL(cyttsp_i2c_read_block_data);
63
64int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf,
Ferruh Yigit62f548d2013-07-04 14:02:57 -070065 u16 addr, u8 length, const void *values)
Ferruh Yigit96648772013-06-30 18:46:56 -070066{
67 struct i2c_client *client = to_i2c_client(dev);
Ferruh Yigit62f548d2013-07-04 14:02:57 -070068 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 };
Ferruh Yigit96648772013-06-30 18:46:56 -070078 int retval;
79
Ferruh Yigit62f548d2013-07-04 14:02:57 -070080 xfer_buf[0] = addr_lo;
Ferruh Yigit96648772013-06-30 18:46:56 -070081 memcpy(&xfer_buf[1], values, length);
82
Ferruh Yigit62f548d2013-07-04 14:02:57 -070083 retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
84 if (retval < 0)
85 return retval;
Ferruh Yigit96648772013-06-30 18:46:56 -070086
Ferruh Yigit62f548d2013-07-04 14:02:57 -070087 return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
Ferruh Yigit96648772013-06-30 18:46:56 -070088}
89EXPORT_SYMBOL_GPL(cyttsp_i2c_write_block_data);
90
91
92MODULE_LICENSE("GPL");
93MODULE_AUTHOR("Cypress");