Loading...
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
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
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");
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * cyttsp_i2c_common.c
4 * Cypress TrueTouch(TM) Standard Product (TTSP) I2C touchscreen driver.
5 * For use with Cypress Txx3xx and Txx4xx parts.
6 * Supported parts include:
7 * CY8CTST341
8 * CY8CTMA340
9 * TMA4XX
10 * TMA1036
11 *
12 * Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc.
13 * Copyright (C) 2012 Javier Martinez Canillas <javier@dowhile0.org>
14 *
15 * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com>
16 */
17
18#include <linux/device.h>
19#include <linux/export.h>
20#include <linux/i2c.h>
21#include <linux/module.h>
22#include <linux/types.h>
23
24#include "cyttsp4_core.h"
25
26int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf,
27 u16 addr, u8 length, void *values)
28{
29 struct i2c_client *client = to_i2c_client(dev);
30 u8 client_addr = client->addr | ((addr >> 8) & 0x1);
31 u8 addr_lo = addr & 0xFF;
32 struct i2c_msg msgs[] = {
33 {
34 .addr = client_addr,
35 .flags = 0,
36 .len = 1,
37 .buf = &addr_lo,
38 },
39 {
40 .addr = client_addr,
41 .flags = I2C_M_RD,
42 .len = length,
43 .buf = values,
44 },
45 };
46 int retval;
47
48 retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
49 if (retval < 0)
50 return retval;
51
52 return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
53}
54EXPORT_SYMBOL_GPL(cyttsp_i2c_read_block_data);
55
56int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf,
57 u16 addr, u8 length, const void *values)
58{
59 struct i2c_client *client = to_i2c_client(dev);
60 u8 client_addr = client->addr | ((addr >> 8) & 0x1);
61 u8 addr_lo = addr & 0xFF;
62 struct i2c_msg msgs[] = {
63 {
64 .addr = client_addr,
65 .flags = 0,
66 .len = length + 1,
67 .buf = xfer_buf,
68 },
69 };
70 int retval;
71
72 xfer_buf[0] = addr_lo;
73 memcpy(&xfer_buf[1], values, length);
74
75 retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
76 if (retval < 0)
77 return retval;
78
79 return retval != ARRAY_SIZE(msgs) ? -EIO : 0;
80}
81EXPORT_SYMBOL_GPL(cyttsp_i2c_write_block_data);
82
83
84MODULE_LICENSE("GPL");
85MODULE_AUTHOR("Cypress");