/*
* Goodix GT9xx touchscreen driver
*
* Copyright (C) 2016 - 2017 Goodix. Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be a reference
* to you, when you are integrating the GOODiX's CTP IC into your system,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* Version: 2.8.0.1
* Release Date: 2017/11/24
*/
//#define DEBUG
#include <linux/irq.h>
#include <linux/platform_device.h>
#ifdef CONFIG_PINCTRL
#include <linux/pinctrl/consumer.h>
#endif
#include <linux/input/mt.h>
#include "gt9xx.h"
#ifdef CONFIG_GTP_COMPAT_CFG
#include "goodix_compat.h"
#endif
#define GOODIX_COORDS_ARR_SIZE 4
#define PROP_NAME_SIZE 24
#define I2C_MAX_TRANSFER_SIZE 255
#define GTP_PEN_BUTTON1 BTN_STYLUS
#define GTP_PEN_BUTTON2 BTN_STYLUS2
static const char *goodix_ts_name = "goodix-ts";
static const char *goodix_input_phys = "input/ts";
struct i2c_client *i2c_connect_client;
static struct proc_dir_entry *gtp_config_proc;
enum doze {
DOZE_DISABLED = 0,
DOZE_ENABLED = 1,
DOZE_WAKEUP = 2,
};
static enum doze doze_status = DOZE_DISABLED;
static int gtp_i2c_test(struct i2c_client *client);
static int gtp_enter_doze(struct goodix_ts_data *ts);
static int gtp_unregister_powermanager(struct goodix_ts_data *ts);
static int gtp_register_powermanager(struct goodix_ts_data *ts);
static int gtp_esd_init(struct goodix_ts_data *ts);
static void gtp_esd_check_func(struct work_struct *);
static int gtp_init_ext_watchdog(struct i2c_client *client);
#ifdef CONFIG_TOUCHSCREEN_COMPAT
#include <linux/lonbon/touchscreen_compat.h>
static struct ctp_compat compat;
static int gtp_should_load_driver(void)
{
if (!ctp_compat_get_current_compat(&compat)
&& compat.vendor == CTP_COMPAT_VENDOR_GOODIX) {
printk(KERN_INFO "*** %s: name:%s, addr:0x%x(%d), int:%d, reset:%d, active:%d\n",
__func__, compat.name, compat.i2c_addr, compat.i2c_bus, compat.int_pin,
compat.reset_pin, compat.active);
return 0;
}
return -1;
}
#endif
/*
* return: 2 - ok, < 0 - i2c transfer error
*/
int gtp_i2c_read(struct i2c_client *client, u8 *buf, int len)
{
unsigned int transfer_length = 0;
unsigned int pos = 0, address = (buf[0] << 8) + buf[1];
unsigned char get_buf[64], addr_buf[2];
int retry, r = 2;
struct i2c_msg msgs[] = {
{
.addr = client->addr,
.flags = !I2C_M_RD,
.buf = &addr_buf[0],
.len = GTP_ADDR_LENGTH,
}, {
.addr = client->addr,
.flags = I2C_M_RD,
}
};
len -= GTP_ADDR_LENGTH;
if (likely(len < sizeof(get_buf))) {
/* code optimize, use stack memory */
msgs[1].buf = &get_buf[0];
} else {
msgs[1].buf = kzalloc(len > I2C_MAX_TRANSFER_SIZE
? I2C_MAX_TRANSFER_SIZE : len, GFP_KERNEL);
if (!msgs[1].buf)
return -ENOMEM;
}
while (pos != len) {
if (unlikely(len - pos > I2C_MAX_TRANSFER_SIZE))
transfer_length = I2C_MAX_TRANSFER_SIZE;
else
transfer_length = len - pos;
msgs[0].buf[0] = (address >> 8) & 0xFF;
msgs[0].buf[1] = address & 0xFF;
msgs[1].len = transfer_length;
for (retry = 0; retry < RETRY_MAX_TIMES; retry++) {
if (likely(i2c_transfer(client->adapter, msgs, 2) == 2)) {
memcpy(&buf[2 + pos], msgs[1].buf, transfer_length);
pos += transfer_length;
address += transfer_length;
break;
}
dev_dbg(&client->dev, "I2c read retry[%d]:0x%x\n",
retry + 1, address);
usleep_range(2000, 2100);
}
if (unlikely(retry == RETRY_MAX_TIMES)) {
dev_err(&client->dev,
"I2c read failed,dev:%02x,reg:%04x,size:%u\n",
client->addr, address, len);
r = -EAGAIN;
goto read_exit;
}
}
read_exit:
if (len >= sizeof(get_buf))
kfree(msgs[1].buf);
return r;
}
/*******************************************************
* Function:
* Write data to the i2c slave device.
* Input:
* client: i2c device.
* buf[0~1]: write start address.
* buf[2~len-1]: data buffer
* len: GTP_ADDR_LENGTH + write bytes count
* Output:
* numbers of i2c_msgs to transfer:
* 1: succeed, otherwise: failed
*********************************************************/
int gtp_i2c_write(struct i2c_client *client, u8 *buf, int len)
{
unsigned int pos = 0, transfer_length = 0;
unsigned int address = (buf[0] << 8) + buf[1];
unsigned char put_buf[64];
int retry, r = 1;
struct i2c_msg msg = {
.addr = client->addr,
.flags = !I2C_M_RD,
};
if (likely(len < sizeof(put_buf))) {
/* code optimize,use stack memory*/
msg.buf = &put_buf[0];
} else {
msg.buf = kmalloc(len > I2C_MAX_TRANSFER_SIZE
? I2C_MAX_TRANSFER_SIZE : len, GFP_KERNEL);
if (!msg.buf)
return -ENOMEM;
}
len -= GTP_ADDR_LENGTH;
while (pos != len) {
if (unlikely(len - pos > I2C_MAX_TRANSFER_SIZE - GTP_ADDR_LENGTH))
transfer_length = I2C_MAX_TRANSFER_SIZE - GTP_ADDR_LENGTH;
else
transfer_length = len - pos;
msg.buf[0] = (unsigned char)((address >> 8) & 0xFF);
msg.buf[1] = (unsigned char)(address & 0xFF);
msg.len = transfer_length + 2;
memcpy(&msg.buf[2], &buf[2 + pos], transfer_length);
for (retry = 0; retry < RETRY_MAX_TIMES; retry++) {
if (likely(i2c_transfer(client->adapter, &msg, 1) == 1)) {
pos += transfer_length;
address += transfer_length;
break;
}
dev_dbg(&client->dev, "I2C write retry[%d]\n", retry + 1);
usleep_range(2000, 2100);
}
if (unlikely(retry == RETRY_MAX_TIMES)) {
dev_err(&client->dev,
"I2c write failed,dev:%02x,reg:%04x,size:%u\n",
client->addr, address, len);
r = -EAGAIN;
goto write_exit;
}
}
write_exit:
if (len + GTP_ADDR_LENGTH >= sizeof(put_buf))
kfree(msg.buf);
return r;
}
/*******************************************************
* Function:
* i2c read twice, compare the results
* Input:
* client: i2c device
* addr: operate address
* rxbuf: read data to store, if compare successful
* len: bytes to read
* Output:
* FAIL: read failed
* SUCCESS: read successful
*********************************************************/
s32 gtp_i2c_read_dbl_check(struct i2c_client *client,
u16 addr, u8 *rxbuf, int len)
{
u8 buf[16] = {0};
u8 confirm_buf[16] = {0};
u8 retry = 0;
if (len + 2 > sizeof(buf)) {
dev_warn(&client->dev,
"%s, only support length less then %zu\n",
__func__, sizeof(buf) - 2);
return FAIL;
}
while (retry++ < 3) {
memset(buf, 0xAA, 16);
buf[0] = (u8)(addr >> 8);
buf[1] = (u8)(addr & 0xFF);
gtp_i2c_read(client, buf, len + 2);
memset(confirm_buf, 0xAB, 16);
confirm_buf[0] = (u8)(addr >> 8);
confirm_buf[1] = (u8)(addr & 0xFF);
gtp_i2c_read(client, confirm_buf, len + 2);
if (!memcmp(buf, confirm_buf, len + 2)) {
memcpy(rxbuf, confirm_buf + 2, len);
return SUCCESS;
}
}
dev_err(&client->dev,
"I2C read 0x%04X, %d bytes, double check failed!\n",
addr, len);
return FAIL;
}
/*******************************************************
* Function:
* Send config.
* Input:
* client: i2c device.
* Output:
* result of i2c write operation.
* 1: succeed, otherwise
* 0: Not executed
* < 0: failed
*********************************************************/
s32 gtp_send_cfg(struct i2c_client *client)
{
s32 ret, i;
u8 check_sum;
s32 retry = 0;
struct goodix_ts_data *ts = i2c_get_clientdata(client);
struct goodix_config_data *cfg = &ts->pdata->config;
if (!cfg->length || !ts->pdata->driver_send_cfg) {
dev_info(&ts->client->dev,
"No config data or error occurred in panel_init\n");
return 0;
}
check_sum = 0;
for (i = GTP_ADDR_LENGTH; i < cfg->length; i++)
check_sum += cfg->data[i];
cfg->data[cfg->length] = (~check_sum) + 1;
dev_info(&ts->client->dev, " Driver send config\n");
for (retry = 0; retry < RETRY_MAX_TIMES; retry++) {
没有合适的资源?快使用搜索试试~ 我知道了~
SSD202D-触摸屏GT9XX-触摸屏兼容功能
共33个文件
cmd:8个
o:7个
cfg:7个
1 下载量 162 浏览量
2023-11-15
11:39:14
上传
评论
收藏 1MB ZIP 举报
温馨提示
SSD202D-触摸屏GT9XX-触摸屏兼容功能
资源推荐
资源详情
资源评论
收起资源包目录
gt9xx.zip (33个子文件)
gt9xx
modules.order 51B
gt9xx.c 69KB
.gt9xx_ts.o.cmd 382B
.gt9xx_ts.ko.cmd 341B
gt9xx_update.o 179KB
Makefile 187B
.built-in.o.cmd 243B
gt9xx.h 9KB
configs
GUJ7183A_COF_1070_1280X800_V80_20230602.cfg 930B
Default_GT911_480X800_ID5_Ver00_20220606_173602.cfg 930B
GTJ6716C_COF_V76_32X18_1024x600_GT9271_20220412_.cfg 929B
Default_GT911_1024X600_ID2_Ver100_20210617_151402.cfg 929B
GT9271-DPT7605_V69_GT9271_Config_20221025_110121.cfg 930B
GTJ6716C_COF_V82_32X18_1024x600_GT9271_20220915.cfg 929B
GTJ6716C_COF_V81_32X18_1024x600_GT9271_20220606.cfg 929B
.gt9xx_update.o.cmd 41KB
Kconfig 301B
.gt9xx_ts.mod.o.cmd 21KB
goodix_tool.o 150KB
goodix_compat.o 139KB
gt9xx_ts.ko 717KB
goodix_compat.h 1KB
goodix_compat.c 11KB
goodix_tool.c 13KB
gt9xx_ts.mod.o 30KB
gt9xx_update.c 56KB
gt9xx.o 229KB
.goodix_tool.o.cmd 41KB
.gt9xx.o.cmd 41KB
gt9xx_ts.o 689KB
.goodix_compat.o.cmd 41KB
gt9xx_ts.mod.c 535B
built-in.o 8B
共 33 条
- 1
资源评论
旋风旋风
- 粉丝: 2979
- 资源: 39
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功