]>
Commit | Line | Data |
---|---|---|
97fb5e8d | 1 | // SPDX-License-Identifier: GPL-2.0-only |
9664877e FY |
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 <[email protected]> | |
14 | * | |
9664877e | 15 | * Contact Cypress Semiconductor at www.cypress.com <[email protected]> |
9664877e FY |
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 | ||
9222d806 RK |
24 | #include "cyttsp4_core.h" |
25 | ||
9664877e | 26 | int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf, |
62f548d0 | 27 | u16 addr, u8 length, void *values) |
9664877e FY |
28 | { |
29 | struct i2c_client *client = to_i2c_client(dev); | |
62f548d0 FY |
30 | u8 client_addr = client->addr | ((addr >> 8) & 0x1); |
31 | u8 addr_lo = addr & 0xFF; | |
9664877e FY |
32 | struct i2c_msg msgs[] = { |
33 | { | |
62f548d0 | 34 | .addr = client_addr, |
9664877e FY |
35 | .flags = 0, |
36 | .len = 1, | |
62f548d0 | 37 | .buf = &addr_lo, |
9664877e FY |
38 | }, |
39 | { | |
62f548d0 | 40 | .addr = client_addr, |
9664877e FY |
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 | } | |
54 | EXPORT_SYMBOL_GPL(cyttsp_i2c_read_block_data); | |
55 | ||
56 | int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, | |
62f548d0 | 57 | u16 addr, u8 length, const void *values) |
9664877e FY |
58 | { |
59 | struct i2c_client *client = to_i2c_client(dev); | |
62f548d0 FY |
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 | }; | |
9664877e FY |
70 | int retval; |
71 | ||
62f548d0 | 72 | xfer_buf[0] = addr_lo; |
9664877e FY |
73 | memcpy(&xfer_buf[1], values, length); |
74 | ||
62f548d0 FY |
75 | retval = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); |
76 | if (retval < 0) | |
77 | return retval; | |
9664877e | 78 | |
62f548d0 | 79 | return retval != ARRAY_SIZE(msgs) ? -EIO : 0; |
9664877e FY |
80 | } |
81 | EXPORT_SYMBOL_GPL(cyttsp_i2c_write_block_data); | |
82 | ||
83 | ||
e17fb91c | 84 | MODULE_DESCRIPTION("Cypress TrueTouch(TM) Standard Product (TTSP) I2C touchscreen driver"); |
9664877e FY |
85 | MODULE_LICENSE("GPL"); |
86 | MODULE_AUTHOR("Cypress"); |