Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * cyttsp_i2c_common.c
0004  * Cypress TrueTouch(TM) Standard Product (TTSP) I2C touchscreen driver.
0005  * For use with Cypress Txx3xx and Txx4xx parts.
0006  * Supported parts include:
0007  * CY8CTST341
0008  * CY8CTMA340
0009  * TMA4XX
0010  * TMA1036
0011  *
0012  * Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc.
0013  * Copyright (C) 2012 Javier Martinez Canillas <javier@dowhile0.org>
0014  *
0015  * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com>
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");