Initial commit: Linux kernel 4.19 for Unplugged OS

This commit is contained in:
ziv committed 2025-10-06 13:52:42 +00:00
commit d30235b04c
80519 files changed
+35800681

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
# Goodix Touchscreen Makefile
# This Makefile is only for tempory compiling use
# Use xxxproject/Makefile-release when release driver
#
# core layer
ccflags-$(CONFIG_DRM_MEDIATEK) += -I$(srctree)/drivers/gpu/drm/mediatek/
obj-y += goodix_ts_i2c.o
obj-y += goodix_ts_core.o
obj-y += goodix_cfg_bin.o
obj-y += goodix_gtx8_update.o
obj-n += goodix_ts_tui.o
@@ -0,0 +1,658 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include "goodix_cfg_bin.h"
#define CFG_TAG ""
int goodix_start_cfg_bin(struct goodix_ts_core *ts_core)
{
struct task_struct *cfg_bin_thrd;
/* create and run update thread */
cfg_bin_thrd = kthread_run(goodix_cfg_bin_proc,
ts_core, "goodix-parse_cfg_bin");
if (IS_ERR_OR_NULL(cfg_bin_thrd)) {
ts_err("Failed to create update thread:%ld",
PTR_ERR(cfg_bin_thrd));
return -EFAULT;
}
return 0;
}
int goodix_parse_cfg_bin(struct goodix_cfg_bin *cfg_bin)
{
u8 checksum;
int i, r;
u16 offset1, offset2;
if (!cfg_bin->bin_data || cfg_bin->bin_data_len == 0) {
ts_err("NO cfg_bin data, cfg_bin data length:%d",
cfg_bin->bin_data_len);
r = -EINVAL;
goto exit;
}
/* copy cfg_bin head info */
if (cfg_bin->bin_data_len < sizeof(struct goodix_cfg_bin_head)) {
ts_err("Invalid cfg_bin size:%d", cfg_bin->bin_data_len);
r = -EINVAL;
goto exit;
}
memcpy(&cfg_bin->head, cfg_bin->bin_data,
sizeof(struct goodix_cfg_bin_head));
cfg_bin->head.bin_len = le32_to_cpu(cfg_bin->head.bin_len);
/*check length*/
if (cfg_bin->bin_data_len != cfg_bin->head.bin_len) {
ts_err("cfg_bin len error,cfg_bin len:%d\n,"
CFG_TAG "len of firmware:%d\n"
, cfg_bin->head.bin_len
, cfg_bin->bin_data_len);
r = -EINVAL;
goto exit;
}
/*check cfg_bin valid*/
checksum = 0;
for (i = TS_BIN_VERSION_START_INDEX; i < cfg_bin->bin_data_len; i++)
checksum += cfg_bin->bin_data[i];
if (checksum != cfg_bin->head.checksum) {
ts_err("cfg_bin checksum ERROR, checksum in cfg_bin:0x%02x,"
CFG_TAG "checksum caculate:0x%02x"
, cfg_bin->head.checksum, checksum);
r = -EINVAL;
goto exit;
}
/*allocate memory for cfg packages*/
cfg_bin->cfg_pkgs =
kzalloc(sizeof(struct goodix_cfg_package) * cfg_bin->head.pkg_num,
GFP_KERNEL);
if (!cfg_bin->cfg_pkgs) {
ts_err("cfg_pkgs, allocate memory ERROR");
r = -ENOMEM;
goto exit;
}
/*get cfg_pkg's info*/
for (i = 0; i < cfg_bin->head.pkg_num; i++) {
/*get cfg pkg length*/
if (i == cfg_bin->head.pkg_num - 1) {
offset1 = cfg_bin->bin_data[TS_CFG_BIN_HEAD_LEN +
i * TS_CFG_OFFSET_LEN] +
(cfg_bin->bin_data[TS_CFG_BIN_HEAD_LEN +
i * TS_CFG_OFFSET_LEN + 1] << 8);
cfg_bin->cfg_pkgs[i].pkg_len = cfg_bin->bin_data_len
- offset1;
} else {
offset1 = cfg_bin->bin_data[TS_CFG_BIN_HEAD_LEN +
i * TS_CFG_OFFSET_LEN] +
(cfg_bin->bin_data[TS_CFG_BIN_HEAD_LEN +
i * TS_CFG_OFFSET_LEN + 1] << 8);
offset2 = cfg_bin->bin_data[TS_CFG_BIN_HEAD_LEN +
i * TS_CFG_OFFSET_LEN + 2] +
(cfg_bin->bin_data[TS_CFG_BIN_HEAD_LEN +
i * TS_CFG_OFFSET_LEN + 3] << 8);
if (offset2 <= offset1) {
ts_err("offset error,pkg:%d, offset1:%d,"
CFG_TAG "offset2:%d"
, i, offset1, offset2);
r = -EINVAL;
goto exit;
}
cfg_bin->cfg_pkgs[i].pkg_len = offset2 - offset1;
}
/*get cfg pkg head*/
memcpy(&cfg_bin->cfg_pkgs[i].cnst_info,
&cfg_bin->bin_data[offset1],
TS_PKG_CONST_INFO_LEN);
memcpy(&cfg_bin->cfg_pkgs[i].reg_info,
&cfg_bin->bin_data[offset1 + TS_PKG_CONST_INFO_LEN],
TS_PKG_REG_INFO_LEN);
/*compatible little edition and big edition*/
goodix_cfg_pkg_leToCpu(&cfg_bin->cfg_pkgs[i]);
/*get configuration data*/
cfg_bin->cfg_pkgs[i].cfg =
&cfg_bin->bin_data[offset1 + TS_PKG_HEAD_LEN];
}
/*debug, print pkg information*/
for (i = 0; i < cfg_bin->head.pkg_num; i++) {
ts_info("---------------------------------------------");
ts_info("------package:%d------", i + 1);
ts_info("package len:%04x",
cfg_bin->cfg_pkgs[i].cnst_info.pkg_len);
ts_info("package ic_type:%s",
cfg_bin->cfg_pkgs[i].cnst_info.ic_type);
ts_info("package cfg_type:%01x",
cfg_bin->cfg_pkgs[i].cnst_info.cfg_type);
ts_info("package sensor_id:%01x",
cfg_bin->cfg_pkgs[i].cnst_info.sensor_id);
ts_info("package hw_pid:%s",
cfg_bin->cfg_pkgs[i].cnst_info.hw_pid);
ts_info("package hw_vid:%s",
cfg_bin->cfg_pkgs[i].cnst_info.hw_vid);
ts_info("package fw_mask_version:%s",
cfg_bin->cfg_pkgs[i].cnst_info.fw_mask);
ts_info("package fw_patch_version:%s",
cfg_bin->cfg_pkgs[i].cnst_info.fw_patch);
ts_info("package x_res_offset:%02x",
cfg_bin->cfg_pkgs[i].cnst_info.x_res_offset);
ts_info("package y_res_offset:%02x",
cfg_bin->cfg_pkgs[i].cnst_info.y_res_offset);
ts_info("package trigger_offset:%02x",
cfg_bin->cfg_pkgs[i].cnst_info.trigger_offset);
ts_info("");
ts_info("send_cfg_flag reg:%02x",
cfg_bin->cfg_pkgs[i].reg_info.cfg_send_flag.addr);
ts_info("version base reg:%02x, len:%d",
cfg_bin->cfg_pkgs[i].reg_info.version_base.addr,
cfg_bin->cfg_pkgs[i].reg_info.version_base.reserved1);
ts_info("pid reg:%02x", cfg_bin->cfg_pkgs[i].reg_info.pid.addr);
ts_info("vid reg:%02x", cfg_bin->cfg_pkgs[i].reg_info.vid.addr);
ts_info("sensor_id reg:%02x",
cfg_bin->cfg_pkgs[i].reg_info.sensor_id.addr);
ts_info("fw_status reg:%02x",
cfg_bin->cfg_pkgs[i].reg_info.fw_status.addr);
ts_info("cfg_addr reg:%02x",
cfg_bin->cfg_pkgs[i].reg_info.cfg_addr.addr);
ts_info("esd reg:%02x", cfg_bin->cfg_pkgs[i].reg_info.esd.addr);
ts_info("command reg:%02x",
cfg_bin->cfg_pkgs[i].reg_info.command.addr);
ts_info("coor:%02x",
cfg_bin->cfg_pkgs[i].reg_info.coor.addr);
ts_info("gesture:%02x",
cfg_bin->cfg_pkgs[i].reg_info.gesture.addr);
ts_info("fw_request:%02x",
cfg_bin->cfg_pkgs[i].reg_info.fw_request.addr);
ts_info("proximity:%02x",
cfg_bin->cfg_pkgs[i].reg_info.proximity.addr);
ts_info("--------------------------------------------");
}
r = 0;
exit:
return r;
}
int goodix_cfg_bin_proc(void *data)
{
struct goodix_ts_core *core_data = data;
struct goodix_ts_device *ts_dev = core_data->ts_dev;
struct device *dev = ts_dev->dev;
int r;
struct goodix_cfg_bin *cfg_bin =
kzalloc(sizeof(struct goodix_cfg_bin), GFP_KERNEL);
if (!cfg_bin) {
ts_err("Failed to alloc memory for cfg_bin");
r = -ENOMEM;
goto out;
}
cfg_bin->cfg_pkgs = NULL;
/*get cfg_bin from file system*/
r = goodix_read_cfg_bin(dev, cfg_bin);
if (r < 0) {
ts_err("read cfg_bin from /etc/firmware FAILED");
goto exit;
}
/*parse cfg bin*/
r = goodix_parse_cfg_bin(cfg_bin);
if (!r) {
ts_info("parse cfg bin SUCCESS");
} else {
ts_err("parse cfg bin FAILED");
goto exit;
}
/*init i2c_set_doze_mode para*/
ts_dev->doze_mode_set_count = 0;
mutex_init(&ts_dev->doze_mode_lock);
/*get register address and configuration from cfg bin*/
r = goodix_get_reg_and_cfg(ts_dev, cfg_bin);
if (!r) {
ts_info("get reg and cfg from cfg_bin SUCCESS");
} else {
if (r != -EBUS) {
ts_err("get reg and cfg from cfg_bin FAILED,"
CFG_TAG "update fw then retry");
goodix_modules.core_data = core_data;
goodix_modules.core_exit = false;
complete_all(&goodix_modules.core_comp);
goto exit;
} else {
ts_err("get reg and cfg from cfg_bin FAILED,"
CFG_TAG "I2C com ERROR");
goto exit;
}
}
/*debug*/
ts_info("@@@@@@@@@");
ts_info("cfg_send_flag:0x%04x", ts_dev->reg.cfg_send_flag);
ts_info("pid:0x%04x", ts_dev->reg.pid);
ts_info("vid:0x%04x", ts_dev->reg.vid);
ts_info("sensor_id:0x%04x", ts_dev->reg.sensor_id);
ts_info("fw_mask:0x%04x", ts_dev->reg.fw_mask);
ts_info("fw_status:0x%04x", ts_dev->reg.fw_status);
ts_info("cfg_addr:0x%04x", ts_dev->reg.cfg_addr);
ts_info("esd:0x%04x", ts_dev->reg.esd);
ts_info("command:0x%04x", ts_dev->reg.command);
ts_info("coor:0x%04x", ts_dev->reg.coor);
ts_info("gesture:0x%04x", ts_dev->reg.gesture);
ts_info("fw_request:0x%04x", ts_dev->reg.fw_request);
ts_info("proximity:0x%04x", ts_dev->reg.proximity);
ts_info("@@@@@@@@@");
/* initialize firmware */
r = ts_dev->hw_ops->init(ts_dev);
if (-EBUS == r)
goto exit;
/* alloc/config/register input device */
r = goodix_ts_input_dev_config(core_data);
if (r < 0)
goto exit;
/* request irq line */
r = goodix_ts_irq_setup(core_data);
if (r < 0)
goto exit;
/*set flag, prevent fwupdate module parse cfg_group again*/
core_data->cfg_group_parsed = true;
/* inform the external module manager that*/
/* touch core layer is ready now */
goodix_modules.core_data = core_data;
goodix_modules.core_exit = false;
/*complete_all(&goodix_modules.core_comp);*/
#ifdef CONFIG_FB
core_data->fb_notifier.notifier_call = goodix_ts_fb_notifier_callback;
if (fb_register_client(&core_data->fb_notifier))
ts_err("Failed to register fb notifier client:%d", r);
#elif defined(CONFIG_HAS_EARLYSUSPEND)
core_data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
core_data->early_suspend.resume = goodix_ts_lateresume;
core_data->early_suspend.suspend = goodix_ts_earlysuspend;
register_early_suspend(&core_data->early_suspend);
#endif
/* esd protector */
#ifdef GT9886_ESD_ENABLE
goodix_ts_esd_init(core_data);
#endif
/* generic notifier callback */
core_data->ts_notifier.notifier_call = goodix_generic_noti_callback;
goodix_ts_register_notifier(&core_data->ts_notifier);
exit:
complete_all(&goodix_modules.core_comp);
if (cfg_bin->cfg_pkgs) {
kfree(cfg_bin->cfg_pkgs);
cfg_bin->cfg_pkgs = NULL;
}
if (cfg_bin->bin_data) {
kfree(cfg_bin->bin_data);
cfg_bin->bin_data = NULL;
}
kfree(cfg_bin);
out:
return r;
}
int goodix_get_reg_and_cfg(struct goodix_ts_device *ts_dev,
struct goodix_cfg_bin *cfg_bin)
{
int i;
u16 addr;
u8 read_len;
struct goodix_cfg_package *normal_pkg, *high_sense_pkg;
char temp_sensor_id = -1;
u8 temp_fw_mask[TS_CFG_BLOCK_FW_MASK_LEN] = {0x00};
u8 temp_pid[TS_CFG_BLOCK_PID_LEN] = {0x00};
int r = -EINVAL;
normal_pkg = NULL;
high_sense_pkg = NULL;
if (!cfg_bin->head.pkg_num || !cfg_bin->cfg_pkgs) {
ts_err("there is none cfg package, pkg_num:%d",
cfg_bin->head.pkg_num);
r = -EINVAL;
goto exit;
}
/*select suitable cfg packages*/
for (i = 0; i < cfg_bin->head.pkg_num; i++) {
/*get ic type*/
if (!strncmp(cfg_bin->cfg_pkgs[i].cnst_info.ic_type, "nanjing",
sizeof(cfg_bin->cfg_pkgs[i].cnst_info.ic_type)))
ts_dev->ic_type = IC_TYPE_NANJING;
else if (!strncmp(cfg_bin->cfg_pkgs[i].cnst_info.ic_type,
"normandy",
sizeof(cfg_bin->cfg_pkgs[i].cnst_info.ic_type)))
ts_dev->ic_type = IC_TYPE_NORMANDY;
else
ts_err("get ic type FAILED,"
CFG_TAG "unknown ic type from cfg_bin:%s",
cfg_bin->cfg_pkgs[i].cnst_info.ic_type);
ts_info("ic_type:%d", ts_dev->ic_type);
/*contrast sensor id*/
addr = cfg_bin->cfg_pkgs[i].reg_info.sensor_id.addr;
if (!addr) {
ts_info("pkg:%d, sensor_id reg is NULL", i);
continue;
}
r = goodix_i2c_read(ts_dev, addr,
&temp_sensor_id, 1);
if (r < 0) {
ts_err("read sensor id FAILED,I2C ERROR, pkg:%d,"
CFG_TAG "sensor_id reg:0x%02x", i, addr);
goto exit;
} else {
/*sensor.reserved1 is a mask, if it's not ZERO, use it*/
if (cfg_bin->cfg_pkgs[i].reg_info.sensor_id.reserved1
!= 0)
temp_sensor_id &=
cfg_bin->cfg_pkgs[i].reg_info.sensor_id.reserved1;
if (temp_sensor_id !=
cfg_bin->cfg_pkgs[i].cnst_info.sensor_id) {
ts_err("pkg:%d, sensor id contrast FAILED,"
CFG_TAG "reg:0x%02x", i, addr);
ts_err("sensor_id from i2c:%d, sensor_id of cfg"
CFG_TAG "bin:%d", temp_sensor_id,
cfg_bin->cfg_pkgs[i].cnst_info.sensor_id);
continue;
}
}
/*contrast fw_mask, if this reg is null, skip this step*/
addr = cfg_bin->cfg_pkgs[i].reg_info.fw_mask.addr;
if (!addr || !cfg_bin->cfg_pkgs[i].cnst_info.fw_mask[0]) {
ts_err("pkg:%d, fw_mask of cfg bin is NULL, Skip!!", i);
} else {
r = goodix_i2c_read(ts_dev, addr, temp_fw_mask,
sizeof(temp_fw_mask));
if (r < 0) {
ts_err("read fw_mask FAILED, I2C ERROR,pkg:"
CFG_TAG "%d, fw_mask reg:0x%02x", i, addr);
goto exit;
} else if (strncmp(temp_fw_mask,
cfg_bin->cfg_pkgs[i].cnst_info.fw_mask,
sizeof(temp_fw_mask))) {
ts_err("pkg:%d, fw_mask contrast FAILED,"
CFG_TAG "reg:0x%02x,", i, addr);
ts_err("mask from i2c:%s, mask of cfg bin:%s",
temp_fw_mask,
cfg_bin->cfg_pkgs[i].cnst_info.fw_mask);
continue;
}
}
/*contrast pid*/
addr = cfg_bin->cfg_pkgs[i].reg_info.pid.addr;
read_len = cfg_bin->cfg_pkgs[i].reg_info.pid.reserved1;
if (!addr) {
ts_err("pkg:%d, pid reg is NULL", i);
continue;
}
if (read_len <= 0 || read_len > TS_CFG_BLOCK_PID_LEN) {
ts_err("pkg:%d, hw_pid len ERROR, len:%d", i, read_len);
continue;
}
r = goodix_i2c_read(ts_dev, addr, temp_pid, read_len);
if (r < 0) {
ts_err("read pid FAILED, I2C ERROR, pkg: %d,"
CFG_TAG "pid reg:0x%02x", i, addr);
goto exit;
} else if (strncmp(temp_pid,\
cfg_bin->cfg_pkgs[i].cnst_info.hw_pid, read_len)) {
ts_err("pkg:%d, pid contrast FAILED,"
CFG_TAG "reg:0x%02x", i, addr);
ts_err("pid from i2c:%s, pid of cfg bin:%s"
, temp_pid,
cfg_bin->cfg_pkgs[i].cnst_info.hw_pid);
continue;
}
/*contrast success, cfg_type*/
if (cfg_bin->cfg_pkgs[i].cnst_info.cfg_type == TS_NORMAL_CFG) {
ts_info("find normal cfg_pkg SUCCESS");
r = 0;
normal_pkg = &cfg_bin->cfg_pkgs[i];
}
if (cfg_bin->cfg_pkgs[i].cnst_info.cfg_type ==
TS_HIGH_SENSE_CFG) {
ts_info("find high sense cfg_pkg SUCCESS");
high_sense_pkg = &cfg_bin->cfg_pkgs[i];
}
}
/*get register address from normal_pkg*/
if (!normal_pkg) {
ts_err("ERROR, none suitable normal_pkg exist in cfg_bin");
/*ts_dev->ic_type = IC_TYPE_NONE;*/
r = -EINVAL;
goto exit;
} else {
/*get ic type*/
if (!strncmp(normal_pkg->cnst_info.ic_type, "nanjing",
sizeof(normal_pkg->cnst_info.ic_type)))
ts_dev->ic_type = IC_TYPE_NANJING;
else if (!strncmp(normal_pkg->cnst_info.ic_type, "normandy",
sizeof(normal_pkg->cnst_info.ic_type)))
ts_dev->ic_type = IC_TYPE_NORMANDY;
else
ts_err("get ic type FAILED, unknown ic type from"
CFG_TAG "cfg_bin:%s"
, normal_pkg->cnst_info.ic_type);
/*get register info*/
ts_dev->reg.cfg_send_flag =
normal_pkg->reg_info.cfg_send_flag.addr;
ts_dev->reg.version_base =
normal_pkg->reg_info.version_base.addr;
ts_dev->reg.version_len =
normal_pkg->reg_info.version_base.reserved1;
ts_dev->reg.pid = normal_pkg->reg_info.pid.addr;
ts_dev->reg.pid_len = normal_pkg->reg_info.pid.reserved1;
ts_dev->reg.vid = normal_pkg->reg_info.vid.addr;
ts_dev->reg.vid_len = normal_pkg->reg_info.vid.reserved1;
ts_dev->reg.sensor_id = normal_pkg->reg_info.sensor_id.addr;
ts_dev->reg.sensor_id_mask =
normal_pkg->reg_info.sensor_id.reserved1;
ts_dev->reg.fw_mask = normal_pkg->reg_info.fw_mask.addr;
ts_dev->reg.fw_status = normal_pkg->reg_info.fw_status.addr;
ts_dev->reg.cfg_addr = normal_pkg->reg_info.cfg_addr.addr;
ts_dev->reg.esd = normal_pkg->reg_info.esd.addr;
ts_dev->reg.command = normal_pkg->reg_info.command.addr;
ts_dev->reg.coor = normal_pkg->reg_info.coor.addr;
ts_dev->reg.gesture = normal_pkg->reg_info.gesture.addr;
ts_dev->reg.fw_request = normal_pkg->reg_info.fw_request.addr;
ts_dev->reg.proximity = normal_pkg->reg_info.proximity.addr;
}
/*get configuration from pkgs*/
if (normal_pkg) {
ts_info("normal cfg is found!");
if (!ts_dev->normal_cfg) {
ts_dev->normal_cfg = devm_kzalloc(ts_dev->dev,
sizeof(*ts_dev->normal_cfg), GFP_KERNEL);
if (!ts_dev->normal_cfg) {
ts_err("Failed to alloc memory for normal cfg");
return -ENOMEM;
}
mutex_init(&ts_dev->normal_cfg->lock);
}
ts_dev->normal_cfg->length = normal_pkg->pkg_len -
TS_PKG_CONST_INFO_LEN - TS_PKG_REG_INFO_LEN;
memcpy(ts_dev->normal_cfg->data, normal_pkg->cfg
, ts_dev->normal_cfg->length);
}
if (high_sense_pkg) {
ts_info("high sense cfg is found!");
if (!ts_dev->highsense_cfg) {
ts_dev->highsense_cfg = devm_kzalloc(ts_dev->dev,
sizeof(*ts_dev->highsense_cfg), GFP_KERNEL);
if (!ts_dev->highsense_cfg) {
ts_err("Failed to alloc"
CFG_TAG " memory for high sense cfg");
return -ENOMEM;
}
mutex_init(&ts_dev->highsense_cfg->lock);
}
ts_dev->highsense_cfg->length = high_sense_pkg->pkg_len -
TS_PKG_CONST_INFO_LEN - TS_PKG_REG_INFO_LEN;
memcpy(ts_dev->highsense_cfg->data,
high_sense_pkg->cfg,
ts_dev->highsense_cfg->length);
}
exit:
return r;
}
int goodix_read_cfg_bin(struct device *dev, struct goodix_cfg_bin *cfg_bin)
{
int r;
const struct firmware *firmware = NULL;
char cfg_bin_name[32] = {0};
int i = 0;
/*get cfg_bin_name*/
r = snprintf(cfg_bin_name, sizeof(cfg_bin_name), "%s%s.bin",
TS_DEFAULT_CFG_BIN, gt9886_config_buf);
if (r >= sizeof(cfg_bin_name)) {
ts_err("get cfg_bin name FAILED!!!");
goto exit;
}
ts_info("cfg_bin_name:%s", cfg_bin_name);
for (i = 0; i < TS_RQST_FW_RETRY_TIMES; i++) {
r = request_firmware(&firmware, cfg_bin_name, dev);
if (r < 0) {
ts_err("Cfg_bin image [%s] not available,error:%d,"
CFG_TAG"try_times:%d", cfg_bin_name, r, i + 1);
msleep(3000);
} else {
ts_info("Cfg_bin image [%s] is ready, try_times:%d",
cfg_bin_name, i + 1);
break;
}
}
if (i >= TS_RQST_FW_RETRY_TIMES) {
ts_err("get cfg_bin FAILED");
goto exit;
}
if (firmware->size <= 0) {
ts_err("request_firmware, cfg_bin length ERROR,len:%zu",
firmware->size);
r = -EINVAL;
goto exit;
}
cfg_bin->bin_data_len = firmware->size;
/*allocate memory for cfg_bin->bin_data*/
cfg_bin->bin_data = kzalloc(cfg_bin->bin_data_len, GFP_KERNEL);
if (!cfg_bin->bin_data) {
ts_err("Allocate memory for cfg_bin->bin_data FAILED");
r = -ENOMEM;
goto exit;
}
memcpy(cfg_bin->bin_data, firmware->data, cfg_bin->bin_data_len);
r = 0;
exit:
if (firmware) {
release_firmware(firmware);
firmware = NULL;
}
return r;
}
int goodix_read_cfg_bin_from_dts(struct device_node *node,
struct goodix_cfg_bin *cfg_bin)
{
unsigned int len = 0;
struct property *prop = NULL;
prop = of_find_property(node, "goodix_cfg_bin", &len);
if (!prop || !prop->value || len == 0) {
ts_err("Invalid cfg type, size:%u", len);
return -EINVAL;
}
cfg_bin->bin_data_len = len;
/*allocate memory for cfg_bin->bin_data*/
cfg_bin->bin_data = kzalloc(cfg_bin->bin_data_len, GFP_KERNEL);
if (!cfg_bin->bin_data) {
ts_err("Allocate memory for cfg_bin->bin_data FAILED");
return -ENOMEM;
}
memcpy(cfg_bin->bin_data, prop->value, cfg_bin->bin_data_len);
return 0;
}
void goodix_cfg_pkg_leToCpu(struct goodix_cfg_package *pkg)
{
if (!pkg) {
ts_err("cfg package is NULL");
return;
}
/*package const_info*/
pkg->cnst_info.pkg_len = le32_to_cpu(pkg->cnst_info.pkg_len);
pkg->cnst_info.x_res_offset = le16_to_cpu(pkg->cnst_info.x_res_offset);
pkg->cnst_info.y_res_offset = le16_to_cpu(pkg->cnst_info.y_res_offset);
pkg->cnst_info.trigger_offset =
le16_to_cpu(pkg->cnst_info.trigger_offset);
/*package reg_info*/
pkg->reg_info.cfg_send_flag.addr =
le16_to_cpu(pkg->reg_info.cfg_send_flag.addr);
pkg->reg_info.pid.addr = le16_to_cpu(pkg->reg_info.pid.addr);
pkg->reg_info.vid.addr = le16_to_cpu(pkg->reg_info.vid.addr);
pkg->reg_info.sensor_id.addr =
le16_to_cpu(pkg->reg_info.sensor_id.addr);
pkg->reg_info.fw_status.addr =
le16_to_cpu(pkg->reg_info.fw_status.addr);
pkg->reg_info.cfg_addr.addr = le16_to_cpu(pkg->reg_info.cfg_addr.addr);
pkg->reg_info.esd.addr = le16_to_cpu(pkg->reg_info.esd.addr);
pkg->reg_info.command.addr = le16_to_cpu(pkg->reg_info.command.addr);
pkg->reg_info.coor.addr = le16_to_cpu(pkg->reg_info.coor.addr);
pkg->reg_info.gesture.addr = le16_to_cpu(pkg->reg_info.gesture.addr);
pkg->reg_info.fw_request.addr =
le16_to_cpu(pkg->reg_info.fw_request.addr);
pkg->reg_info.proximity.addr =
le16_to_cpu(pkg->reg_info.proximity.addr);
}
@@ -0,0 +1,124 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef _GOODIX_CFG_BIN_H_
#define _GOODIX_CFG_BIN_H_
#include "goodix_ts_core.h"
#define TS_DEFAULT_FIRMWARE "gt9886_firmware_"
#define TS_DEFAULT_CFG_BIN "gt9886_cfg_"
extern const char *gt9886_firmware_buf;
extern const char *gt9886_config_buf;
#define TS_BIN_VERSION_START_INDEX 5
#define TS_BIN_VERSION_LEN 4
#define TS_CFG_BIN_HEAD_RESERVED_LEN 6
#define TS_CFG_OFFSET_LEN 2
#define TS_IC_TYPE_NAME_MAX_LEN 15
#define TS_CFG_BIN_HEAD_LEN \
(sizeof(struct goodix_cfg_bin_head) + TS_CFG_BIN_HEAD_RESERVED_LEN)
#define TS_PKG_CONST_INFO_LEN (sizeof(struct goodix_cfg_pkg_const_info))
#define TS_PKG_REG_INFO_LEN (sizeof(struct goodix_cfg_pkg_reg_info))
#define TS_PKG_HEAD_LEN (TS_PKG_CONST_INFO_LEN + TS_PKG_REG_INFO_LEN)
/*cfg block definitin*/
#define TS_CFG_BLOCK_PID_LEN 8
#define TS_CFG_BLOCK_VID_LEN 8
#define TS_CFG_BLOCK_FW_MASK_LEN 9
#define TS_CFG_BLOCK_FW_PATCH_LEN 4
#define TS_CFG_BLOCK_RESERVED_LEN 9
#define TS_NORMAL_CFG 0x01
#define TS_HIGH_SENSE_CFG 0x03
#define TS_RQST_FW_RETRY_TIMES 5
#pragma pack(1)
struct goodix_cfg_pkg_reg {
u16 addr;
u8 reserved1;
u8 reserved2;
};
struct goodix_cfg_pkg_const_info {
u32 pkg_len;
u8 ic_type[TS_IC_TYPE_NAME_MAX_LEN];
u8 cfg_type;
u8 sensor_id;
u8 hw_pid[TS_CFG_BLOCK_PID_LEN];
u8 hw_vid[TS_CFG_BLOCK_VID_LEN];
u8 fw_mask[TS_CFG_BLOCK_FW_MASK_LEN];
u8 fw_patch[TS_CFG_BLOCK_FW_PATCH_LEN];
u16 x_res_offset;
u16 y_res_offset;
u16 trigger_offset;
};
struct goodix_cfg_pkg_reg_info {
struct goodix_cfg_pkg_reg cfg_send_flag;
struct goodix_cfg_pkg_reg version_base;
struct goodix_cfg_pkg_reg pid;
struct goodix_cfg_pkg_reg vid;
struct goodix_cfg_pkg_reg sensor_id;
struct goodix_cfg_pkg_reg fw_mask;
struct goodix_cfg_pkg_reg fw_status;
struct goodix_cfg_pkg_reg cfg_addr;
struct goodix_cfg_pkg_reg esd;
struct goodix_cfg_pkg_reg command;
struct goodix_cfg_pkg_reg coor;
struct goodix_cfg_pkg_reg gesture;
struct goodix_cfg_pkg_reg fw_request;
struct goodix_cfg_pkg_reg proximity;
u8 reserved[TS_CFG_BLOCK_RESERVED_LEN];
};
struct goodix_cfg_bin_head {
u32 bin_len;
u8 checksum;
u8 bin_version[TS_BIN_VERSION_LEN];
u8 pkg_num;
};
#pragma pack()
struct goodix_cfg_package {
struct goodix_cfg_pkg_const_info cnst_info;
struct goodix_cfg_pkg_reg_info reg_info;
const u8 *cfg;
u32 pkg_len;
};
struct goodix_cfg_bin {
unsigned char *bin_data;
unsigned int bin_data_len;
struct goodix_cfg_bin_head head;
struct goodix_cfg_package *cfg_pkgs;
};
int goodix_cfg_bin_proc(void *data);
int goodix_parse_cfg_bin(struct goodix_cfg_bin *cfg_bin);
int goodix_get_reg_and_cfg(struct goodix_ts_device *ts_dev,
struct goodix_cfg_bin *cfg_bin);
int goodix_read_cfg_bin(struct device *dev, struct goodix_cfg_bin *cfg_bin);
int goodix_read_cfg_bin_from_dts(struct device_node *node,
struct goodix_cfg_bin *cfg_bin);
void goodix_cfg_pkg_leToCpu(struct goodix_cfg_package *pkg);
int goodix_start_cfg_bin(struct goodix_ts_core *ts_core);
extern int goodix_i2c_write(struct goodix_ts_device *dev, unsigned int reg,
unsigned char *data, unsigned int len);
extern int goodix_i2c_read(struct goodix_ts_device *dev, unsigned int reg,
unsigned char *data, unsigned int len);
extern struct goodix_module goodix_modules;
#endif
@@ -0,0 +1,10 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef _GOODIX_FIRMWARE_FW_H_
#define _GOODIX_FIRMWARE_FW_H_
u8 goodix_default_fw[] = { 0x00};
#endif
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,752 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef _GOODIX_TS_CORE_H_
#define _GOODIX_TS_CORE_H_
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/firmware.h>
#include <linux/slab.h>
#include <asm/unaligned.h>
#include <linux/vmalloc.h>
#include <linux/kthread.h>
#include <linux/version.h>
#include <linux/delay.h>
#include <linux/mutex.h>
#include <linux/platform_device.h>
#include <linux/input.h>
#include <linux/interrupt.h>
#include <linux/completion.h>
#include <linux/debugfs.h>
#include <linux/of_irq.h>
#ifdef CONFIG_OF
#include <linux/of_gpio.h>
#include <linux/regulator/consumer.h>
#endif
#ifdef CONFIG_HAS_EARLYSUSPEND
#include <linux/earlysuspend.h>
#endif
#ifdef CONFIG_FB
#include <linux/notifier.h>
#include <linux/fb.h>
#endif
/* macros definition */
/* mtk touch factory test: "mtk-tpd2" */
#define GOODIX_CORE_DRIVER_NAME "gt9886"
#define GOODIX_INPUT_DEV_NAME "mtk-tpd2"
#define GOODIX_DRIVER_VERSION "v1.2.0.1"
#define GOODIX_TS_PID_GT9886 "9886"
#define GOODIX_TS_PID_GT9885 "9885"
#define GOODIX_BUS_RETRY_TIMES 3
#define GOODIX_CHIPID_RETRY_TIMES 5
#define GOODIX_MAX_TOUCH 10
#define GOODIX_MAX_PEN 1
#define GOODIX_MAX_KEY 3
#define GOODIX_PEN_MAX_KEY 2
#define GOODIX_CFG_MAX_SIZE 1024
#define GOODIX_ESD_TICK_WRITE_DATA 0xAA
#define GOODIX_PID_MAX_LEN 8
#define GOODIX_VID_MAX_LEN 8
#define GOODIX_DEFAULT_CFG_NAME "goodix_config.cfg"
#define IC_TYPE_NONE 0
#define IC_TYPE_NORMANDY 1
#define IC_TYPE_NANJING 2
#define PINCTRL_STATE_I2C_DEFAULT "ts_i2c_mode"
#define PINCTRL_STATE_INT_ACTIVE "ts_int_active"
#define PINCTRL_STATE_RST_ACTIVE "ts_reset_active"
#define PINCTRL_STATE_INT_SUSPEND "ts_int_suspend"
#define PINCTRL_STATE_RST_SUSPEND "ts_reset_suspend"
#define GOODIX_TOUCH_EVENT 0x80
#define GOODIX_REQUEST_EVENT 0x40
#define GOODIX_GESTURE_EVENT 0x20
#define GOODIX_HOTKNOT_EVENT 0x10
/* For MTK Internal Touch Begin */
/* touch-filter Begin */
struct tpd_filter_t {
int enable; /*0: disable, 1: enable*/
int pixel_density; /*XXX pixel/cm*/
int W_W[3][4];/*filter custom setting prameters*/
unsigned int VECLOCITY_THRESHOLD[3];/*filter speed custom settings*/
};
#define TOUCH_IOC_MAGIC 'A'
#define TPD_GET_FILTER_PARA _IOWR(TOUCH_IOC_MAGIC, 2, struct tpd_filter_t)
#ifdef CONFIG_COMPAT
#define COMPAT_TPD_GET_FILTER_PARA _IOWR(TOUCH_IOC_MAGIC, \
2, struct tpd_filter_t)
#endif
/*
* struct goodix_module - external modules container
* @head: external modules list
* @initilized: whether this struct is initialized
* @mutex: mutex lock
* @count: current number of registered external module
* @wq: workqueue to do register work
* @core_exit: if goodix touch core exit, then no
* registration is allowed.
* @core_data: core_data pointer
*/
struct goodix_module {
struct list_head head;
bool initilized;
struct mutex mutex;
unsigned int count;
struct workqueue_struct *wq;
bool core_exit;
struct completion core_comp;
struct goodix_ts_core *core_data;
};
/*
* struct goodix_ts_board_data - board data
* @avdd_name: name of analoy regulator
* @reset_gpio: reset gpio number
* @irq_gpio: interrupt gpio number
* @irq_flag: irq trigger type
* @power_on_delay_us: power on delay time (us)
* @power_off_delay_us: power off delay time (us)
* @swap_axis: whether swaw x y axis
* @panel_max_id: max supported fingers
* @panel_max_x/y/w/p: resolution and size
* @panel_max_key: max supported keys
* @pannel_key_map: key map
* @fw_name: name of the firmware image
*/
struct goodix_ts_board_data {
const char *avdd_name;
unsigned int reset_gpio;
unsigned int irq_gpio;
int irq;
unsigned int irq_flags;
unsigned int power_on_delay_us;
unsigned int power_off_delay_us;
/* For MTK Internal Touch Begin */
unsigned int input_max_x;
unsigned int input_max_y;
/* For MTK Internal Touch End */
unsigned int swap_axis;
unsigned int panel_max_id; /*max touch id*/
unsigned int panel_max_x;
unsigned int panel_max_y;
unsigned int panel_max_w; /*major and minor*/
unsigned int panel_max_p; /*pressure*/
unsigned int panel_max_key;
unsigned int panel_key_map[GOODIX_MAX_KEY + GOODIX_PEN_MAX_KEY];
/*add by lishuai*/
unsigned int x2x;
unsigned int y2y;
bool pen_enable;
unsigned int tp_key_num;
/*add end*/
const char *fw_name;
const char *cfg_bin_name;
bool esd_default_on;
struct device *pinctrl_dev;
struct tpd_filter_t tpd_filter;
};
/*
* struct goodix_ts_config - chip config data
* @initialized: whether initialized
* @name: name of this config
* @lock: mutex
* @reg_base: register base of config data
* @length: bytes of the config
* @delay: delay time after sending config
* @data: config data buffer
*/
struct goodix_ts_config {
bool initialized;
char name[24];
struct mutex lock;
unsigned int reg_base;
unsigned int length;
unsigned int delay; /*ms*/
unsigned char data[GOODIX_CFG_MAX_SIZE];
};
/*
* struct goodix_ts_cmd - command package
* @initialized: whether initialized
* @cmd_reg: command register
* @length: command length in bytes
* @cmds: command data
*/
#pragma pack(4)
struct goodix_ts_cmd {
u32 initialized;
u32 cmd_reg;
u32 length;
u8 cmds[3];
};
#pragma pack()
/* interrupt event type */
enum ts_event_type {
EVENT_INVALID,
EVENT_TOUCH,
EVENT_REQUEST,
};
/* requset event type */
enum ts_request_type {
REQUEST_INVALID,
REQUEST_CONFIG,
REQUEST_BAKREF,
REQUEST_RESET,
REQUEST_MAINCLK,
};
/* notifier event */
enum ts_notify_event {
NOTIFY_FWUPDATE_START,
NOTIFY_FWUPDATE_END,
NOTIFY_SUSPEND,
NOTIFY_RESUME,
NOTIFY_ESD_OFF,
NOTIFY_ESD_ON,
};
/* coordinate package */
struct goodix_ts_coords {
int id;
unsigned int x, y, w, p;
};
/* touch event data */
struct goodix_touch_data {
/* finger */
int touch_num;
struct goodix_ts_coords coords[GOODIX_MAX_TOUCH];
/* key */
u8 key_value;
bool have_key;
/*pen*/
struct goodix_ts_coords pen_coords[GOODIX_MAX_PEN];
bool pen_down;
};
/* request event data */
struct goodix_request_data {
enum ts_request_type request_type;
};
/*
* struct goodix_ts_event - touch event struct
* @event_type: touch event type, touch data or
* request event
* @event_data: event data
*/
struct goodix_ts_event {
enum ts_event_type event_type;
union {
struct goodix_touch_data touch_data;
struct goodix_request_data request_data;
} event_data;
};
/*
* struct goodix_ts_version - firmware version
* @valid: whether these information is valid
* @pid: product id string
* @vid: firmware version code
* @cid: customer id code
* @sensor_id: sendor id
*/
struct goodix_ts_version {
bool valid;
char pid[GOODIX_PID_MAX_LEN];
char vid[GOODIX_VID_MAX_LEN];
u8 cid;
u8 sensor_id;
};
struct goodix_ts_regs {
u16 cfg_send_flag;
u16 version_base;
u8 version_len;
u16 pid;
u8 pid_len;
u16 vid;
u8 vid_len;
u16 sensor_id;
u8 sensor_id_mask;
u16 fw_mask;
u16 fw_status;
u16 cfg_addr;
u16 esd;
u16 command;
u16 coor;
u16 gesture;
u16 fw_request;
u16 proximity;
};
/*
* struct goodix_ts_device - ts device data
* @name: device name
* @version: reserved
* @bus_type: i2c or spi
* @board_data: board data obtained from dts
* @normal_cfg: normal config data
* @highsense_cfg: high sense config data
* @hw_ops: hardware operations
* @chip_version: firmware version information
* @sleep_cmd: sleep commang
* @gesture_cmd: gesture command
* @dev: device pointer,may be a i2c or spi device
* @of_node: device node
*/
struct goodix_ts_device {
char *name;
int version;
int bus_type;
u8 ic_type;
struct goodix_ts_regs reg;
int doze_mode_set_count;
struct mutex doze_mode_lock;
struct goodix_ts_board_data *board_data;
struct goodix_ts_config *normal_cfg;
struct goodix_ts_config *highsense_cfg;
const struct goodix_ts_hw_ops *hw_ops;
struct goodix_ts_version chip_version;
struct device *dev;
};
/*
* struct goodix_ts_hw_ops - hardware opeartions
* @init: hardware initialization
* @reset: hardware reset
* @read: read data from touch device
* @write: write data to touch device
* @send_cmd: send command to touch device
* @send_config: send configuration data
* @read_version: read firmware version
* @event_handler: touch event handler
* @suspend: put touch device into low power mode
* @resume: put touch device into working mode
*/
struct goodix_ts_hw_ops {
int (*init)(struct goodix_ts_device *dev);
int (*dev_confirm)(struct goodix_ts_device *ts_dev);
int (*reset)(struct goodix_ts_device *dev);
int (*read)(struct goodix_ts_device *dev, unsigned int addr,
unsigned char *data, unsigned int len);
int (*write)(struct goodix_ts_device *dev, unsigned int addr,
unsigned char *data, unsigned int len);
int (*read_trans)(struct goodix_ts_device *dev, unsigned int addr,
unsigned char *data, unsigned int len);
int (*write_trans)(struct goodix_ts_device *dev, unsigned int addr,
unsigned char *data, unsigned int len);
int (*send_cmd)(struct goodix_ts_device *dev,
struct goodix_ts_cmd *cmd);
int (*send_config)(struct goodix_ts_device *dev,
struct goodix_ts_config *config);
int (*read_config)(struct goodix_ts_device *dev,
u8 *config_data, u32 config_len);
int (*read_version)(struct goodix_ts_device *dev,
struct goodix_ts_version *version);
int (*event_handler)(struct goodix_ts_device *dev,
struct goodix_ts_event *ts_event);
int (*check_hw)(struct goodix_ts_device *dev);
int (*suspend)(struct goodix_ts_device *dev);
int (*resume)(struct goodix_ts_device *dev);
int (*read_pid)(struct goodix_ts_device *dev,
struct goodix_ts_version *version);
};
/*
* struct goodix_ts_esd - esd protector structure
* @esd_work: esd delayed work
* @esd_on: true - turn on esd protection, false - turn
* off esd protection
* @esd_mutex: protect @esd_on flag
*/
struct goodix_ts_esd {
struct delayed_work esd_work;
struct mutex esd_mutex;
struct notifier_block esd_notifier;
struct goodix_ts_core *ts_core;
bool esd_on;
};
/*
* struct godix_ts_core - core layer data struct
* @pdev: core layer platform device
* @ts_dev: hardware layer touch device
* @input_dev: input device
* @avdd: analog regulator
* @pinctrl: pinctrl handler
* @pin_sta_active: active/normal pin state
* @pin_sta_suspend: suspend/sleep pin state
* @ts_event: touch event data struct
* @power_on: power on/off flag
* @irq: irq number
* @irq_enabled: irq enabled/disabled flag
* @suspended: suspend/resume flag
* @ts_notifier: generic notifier
* @ts_esd: esd protector structure
* @fb_notifier: framebuffer notifier
* @early_suspend: early suspend
*/
struct goodix_ts_core {
struct platform_device *pdev;
struct goodix_ts_device *ts_dev;
struct input_dev *input_dev;
struct regulator *avdd;
#ifdef CONFIG_PINCTRL
struct pinctrl *pinctrl;
struct pinctrl_state *pin_i2c_mode_default;
struct pinctrl_state *pin_int_sta_active;
struct pinctrl_state *pin_int_sta_suspend;
struct pinctrl_state *pin_rst_sta_active;
struct pinctrl_state *pin_rst_sta_suspend;
#endif
struct goodix_ts_event ts_event;
int power_on;
int irq;
size_t irq_trig_cnt;
atomic_t irq_enabled;
atomic_t suspended;
bool cfg_group_parsed;
struct notifier_block ts_notifier;
struct goodix_ts_esd ts_esd;
#ifdef CONFIG_FB
struct notifier_block fb_notifier;
#elif defined(CONFIG_HAS_EARLYSUSPEND)
struct early_suspend early_suspend;
#endif
};
/* external module structures */
enum goodix_ext_priority {
EXTMOD_PRIO_RESERVED = 0,
EXTMOD_PRIO_FWUPDATE,
EXTMOD_PRIO_GESTURE,
EXTMOD_PRIO_HOTKNOT,
EXTMOD_PRIO_DBGTOOL,
EXTMOD_PRIO_DEFAULT,
};
struct goodix_ext_module;
/* external module's operations callback */
struct goodix_ext_module_funcs {
int (*init)(struct goodix_ts_core *core_data,
struct goodix_ext_module *module);
int (*exit)(struct goodix_ts_core *core_data,
struct goodix_ext_module *module);
int (*before_reset)(struct goodix_ts_core *core_data,
struct goodix_ext_module *module);
int (*after_reset)(struct goodix_ts_core *core_data,
struct goodix_ext_module *module);
int (*before_suspend)(struct goodix_ts_core *core_data,
struct goodix_ext_module *module);
int (*after_suspend)(struct goodix_ts_core *core_data,
struct goodix_ext_module *module);
int (*before_resume)(struct goodix_ts_core *core_data,
struct goodix_ext_module *module);
int (*after_resume)(struct goodix_ts_core *core_data,
struct goodix_ext_module *module);
int (*irq_event)(struct goodix_ts_core *core_data,
struct goodix_ext_module *module);
};
/*
* struct goodix_ext_module - external module struct
* @list: list used to link into modules manager
* @name: name of external module
* @priority: module priority vlaue, zero is invalid
* @funcs: operations callback
* @priv_data: private data region
* @kobj: kobject
* @work: used to queue one work to do registration
*/
struct goodix_ext_module {
struct list_head list;
char *name;
enum goodix_ext_priority priority;
const struct goodix_ext_module_funcs *funcs;
void *priv_data;
struct kobject kobj;
struct work_struct work;
};
/*
* struct goodix_ext_attribute - exteranl attribute struct
* @attr: attribute
* @show: show interface of external attribute
* @store: store interface of external attribute
*/
struct goodix_ext_attribute {
struct attribute attr;
ssize_t (*show)(struct goodix_ext_module *, char *);
ssize_t (*store)(struct goodix_ext_module *, const char *, size_t);
};
/* external attrs helper macro */
#define __EXTMOD_ATTR(_name, _mode, _show, _store) { \
.attr = {.name = __stringify(_name), .mode = _mode }, \
.show = _show, \
.store = _store, \
}
/* external attrs helper macro, used to define external attrs */
#define DEFINE_EXTMOD_ATTR(_name, _mode, _show, _store) \
static struct goodix_ext_attribute ext_attr_##_name = \
__EXTMOD_ATTR(_name, _mode, _show, _store);
/*
* get board data pointer
*/
static inline struct goodix_ts_board_data *board_data(
struct goodix_ts_core *core)
{
return core->ts_dev->board_data;
}
/*
* get touch device pointer
*/
static inline struct goodix_ts_device *ts_device(
struct goodix_ts_core *core)
{
return core->ts_dev;
}
/*
* get touch hardware operations pointer
*/
static inline const struct goodix_ts_hw_ops *ts_hw_ops(
struct goodix_ts_core *core)
{
return core->ts_dev->hw_ops;
}
/*
* checksum helper functions
* checksum can be u8/le16/be16/le32/be32 format
* NOTE: the caller should be responsible for the
* legality of @data and @size parameters, so be
* careful when call these functions.
*/
static inline u8 checksum_u8(u8 *data, u32 size)
{
u8 checksum = 0;
u32 i;
for (i = 0; i < size; i++)
checksum += data[i];
return checksum;
}
static inline u16 checksum_le16(u8 *data, u32 size)
{
u16 checksum = 0;
u32 i;
for (i = 0; i < size; i += 2)
checksum += le16_to_cpup((__le16 *)(data + i));
return checksum;
}
static inline u16 checksum_be16(u8 *data, u32 size)
{
u16 checksum = 0;
u32 i;
for (i = 0; i < size; i += 2)
checksum += be16_to_cpup((__be16 *)(data + i));
return checksum;
}
static inline u32 checksum_le32(u8 *data, u32 size)
{
u32 checksum = 0;
u32 i;
for (i = 0; i < size; i += 4)
checksum += le32_to_cpup((__le32 *)(data + i));
return checksum;
}
static inline u32 checksum_be32(u8 *data, u32 size)
{
u32 checksum = 0;
u32 i;
for (i = 0; i < size; i += 4)
checksum += be32_to_cpup((__be32 *)(data + i));
return checksum;
}
/**
* define event action
* EVT_xxx macros are used in opeartions callback
* defined in @goodix_ext_module_funcs to control
* the behaviors of event such as suspend/resume/irq_event.
* generally there are two types of behaviors:
* 1. you want the flow of this event be canceled,
* in this condition, you should return EVT_CANCEL_XXX in
* the operations callback.
* e.g. the firmware update module is updating
* the firmware, you want to cancel suspend flow,
* so you need to return EVT_CANCEL_SUSPEND in
* suspend callback function.
* 2. you want the flow of this event continue, in
* this condition, you should return EVT_HANDLED in
* the callback function.
*/
#define EVT_HANDLED 0
#define EVT_CONTINUE 0
#define EVT_CANCEL 1
#define EVT_CANCEL_IRQEVT 1
#define EVT_CANCEL_SUSPEND 1
#define EVT_CANCEL_RESUME 1
#define EVT_CANCEL_RESET 1
/*
* errno define
* Note:
* 1. bus read/write functions defined in hardware
* layer code(e.g. goodix_xxx_i2c.c) *must* return
* -EBUS if failed to transfer data on bus.
*/
#define EBUS 1000
#define ETIMEOUT 1001
#define ECHKSUM 1002
#define EMEMCMP 1003
#if 0
#define CONFIG_GOODIX_DEBUG
#endif
/* log macro */
#define ts_info(fmt, arg...)\
pr_info("[GT9886-INF][%s:%d] "fmt"\n", __func__, __LINE__, ##arg)
#define ts_err(fmt, arg...)\
pr_info("[GT9886-ERR][%s:%d] "fmt"\n", __func__, __LINE__, ##arg)
#define boot_log(fmt, arg...) g_info(fmt, ##arg)
#ifdef CONFIG_GOODIX_DEBUG
#define ts_debug(fmt, arg...)\
pr_info("[GT9886-DBG][%s:%d] "fmt"\n", __func__, __LINE__, ##arg)
#else
#define ts_debug(fmt, arg...) do {} while (0)
#endif
/**
* goodix_register_ext_module - interface for external module
* to register into touch core modules structure
*
* @module: pointer to external module to be register
* return: 0 ok, <0 failed
*/
int goodix_register_ext_module(struct goodix_ext_module *module);
/**
* goodix_unregister_ext_module - interface for external module
* to unregister external modules
*
* @module: pointer to external module
* return: 0 ok, <0 failed
*/
int goodix_unregister_ext_module(struct goodix_ext_module *module);
/**
* goodix_ts_irq_enable - Enable/Disable a irq
* @core_data: pointer to touch core data
* enable: enable or disable irq
* return: 0 ok, <0 failed
*/
int goodix_ts_irq_enable(struct goodix_ts_core *core_data, bool enable);
struct kobj_type *goodix_get_default_ktype(void);
/**
* fb_notifier_call_chain - notify clients of fb_events
* see enum ts_notify_event in goodix_ts_core.h
*/
int goodix_ts_blocking_notify(enum ts_notify_event evt, void *v);
/**
* goodix_ts_power_on - Turn on power to the touch device
* @core_data: pointer to touch core data
* return: 0 ok, <0 failed
*/
int goodix_ts_power_on(struct goodix_ts_core *core_data);
/**
* goodix_ts_power_off - Turn off power to the touch device
* @core_data: pointer to touch core data
* return: 0 ok, <0 failed
*/
int goodix_ts_power_off(struct goodix_ts_core *core_data);
int goodix_ts_hw_init(struct goodix_ts_core *core_data);
int goodix_ts_input_dev_config(struct goodix_ts_core *core_data);
int goodix_ts_irq_setup(struct goodix_ts_core *core_data);
int goodix_ts_sysfs_init(struct goodix_ts_core *core_data);
int goodix_ts_esd_init(struct goodix_ts_core *core);
int goodix_ts_register_notifier(struct notifier_block *nb);
int goodix_generic_noti_callback(struct notifier_block *self,
unsigned long action, void *data);
int goodix_ts_fb_notifier_callback(struct notifier_block *self,
unsigned long event, void *data);
int goodix_ts_irq_enable(struct goodix_ts_core *core_data,
bool enable);
extern void goodix_msg_printf(const char *fmt, ...);
extern int i2c_touch_resume(void);
extern int i2c_touch_suspend(void);
extern int goodix_start_cfg_bin(struct goodix_ts_core *ts_core);
int gt9886_touch_filter_register(void);
int goodix_ts_core_init(void);
#ifdef CONFIG_TRUSTONIC_TRUSTED_UI
extern atomic_t gt9886_tui_flag;
extern struct goodix_ts_core *resume_core_data;
#endif
#endif
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,619 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/atomic.h>
#include <linux/miscdevice.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/fs.h>
#include <linux/list.h>
#include <linux/ioctl.h>
#include <linux/wait.h>
#include "goodix_ts_core.h"
#define GOODIX_TOOLS_NAME "gtp_tools"
#define GOODIX_TS_IOC_MAGIC 'G'
#define NEGLECT_SIZE_MASK (~(_IOC_SIZEMASK << _IOC_SIZESHIFT))
#define GTP_IRQ_ENABLE _IO(GOODIX_TS_IOC_MAGIC, 0)
#define GTP_DEV_RESET _IO(GOODIX_TS_IOC_MAGIC, 1)
#define GTP_SEND_COMMAND (_IOW(GOODIX_TS_IOC_MAGIC, 2, u8) & NEGLECT_SIZE_MASK)
#define GTP_SEND_CONFIG (_IOW(GOODIX_TS_IOC_MAGIC, 3, u8) & NEGLECT_SIZE_MASK)
#define GTP_ASYNC_READ (_IOR(GOODIX_TS_IOC_MAGIC, 4, u8) & NEGLECT_SIZE_MASK)
#define GTP_SYNC_READ (_IOR(GOODIX_TS_IOC_MAGIC, 5, u8) & NEGLECT_SIZE_MASK)
#define GTP_ASYNC_WRITE (_IOW(GOODIX_TS_IOC_MAGIC, 6, u8) & NEGLECT_SIZE_MASK)
#define GTP_READ_CONFIG (_IOW(GOODIX_TS_IOC_MAGIC, 7, u8) & NEGLECT_SIZE_MASK)
#define GTP_ESD_ENABLE _IO(GOODIX_TS_IOC_MAGIC, 8)
#define GTP_DRV_VERSION (_IOR(GOODIX_TS_IOC_MAGIC, 9, u8) & NEGLECT_SIZE_MASK)
#define GOODIX_TS_IOC_MAXNR 10
#define IRQ_FALG (0x01 << 2)
#define I2C_MSG_HEAD_LEN 20
#define TS_REG_COORDS_BASE 0x4100
/*
* struct goodix_tools_data - goodix tools data message used in sync read
* @data: The buffer into which data is written
* @reg_addr: Slave device register start address to start read data
* @length: Number of data bytes in @data being read from slave device
* @filled: When buffer @data be filled will set this flag with 1, outhrwise 0
* @list_head:Eonnet every goodix_tools_data struct into a list
*/
struct goodix_tools_data {
u32 reg_addr;
u32 length;
u8 *data;
bool filled;
struct list_head list;
};
/*
* struct goodix_tools_dev - goodix tools device struct
* @ts_core: The core data struct of ts driver
* @ops_mode: represent device work mode
* @rawdiffcmd: Set slave device into rawdata mode
* @normalcmd: Set slave device into normal mode
* @wq: Wait queue struct use in synchronous data read
* @mutex: Protect goodix_tools_dev
*/
struct goodix_tools_dev {
struct goodix_ts_core *ts_core;
struct list_head head;
unsigned int ops_mode;
struct goodix_ts_cmd rawdiffcmd, normalcmd;
wait_queue_head_t wq;
struct mutex mutex;
atomic_t t_count;
struct goodix_ext_module module;
} *goodix_tools_dev;
/* read data from i2c asynchronous,
* success return bytes read, else return <= 0
*/
static int async_read(struct goodix_tools_dev *dev, void __user *arg)
{
u8 *databuf = NULL;
int ret = 0;
u32 reg_addr, length;
u8 i2c_msg_head[I2C_MSG_HEAD_LEN];
struct goodix_ts_device *ts_dev = dev->ts_core->ts_dev;
const struct goodix_ts_hw_ops *hw_ops = ts_dev->hw_ops;
ret = copy_from_user(&i2c_msg_head, arg, I2C_MSG_HEAD_LEN);
if (ret) {
ret = -EFAULT;
goto err_out;
}
reg_addr = i2c_msg_head[0] + (i2c_msg_head[1] << 8)
+ (i2c_msg_head[2] << 16) + (i2c_msg_head[3] << 24);
length = i2c_msg_head[4] + (i2c_msg_head[5] << 8)
+ (i2c_msg_head[6] << 16) + (i2c_msg_head[7] << 24);
if (length > GOODIX_CFG_MAX_SIZE)
return -EMSGSIZE;
databuf = kzalloc(length, GFP_KERNEL);
if (!databuf) {
ts_err("Alloc memory failed");
return -ENOMEM;
}
if (!hw_ops->read_trans(ts_dev, reg_addr, databuf, length)) {
if (copy_to_user((u8 *)arg + I2C_MSG_HEAD_LEN,
databuf, length)) {
ret = -EFAULT;
ts_err("Copy_to_user failed");
} else {
ret = length;
}
} else {
ret = -EBUSY;
ts_err("Read i2c failed");
}
err_out:
kfree(databuf);
return ret;
}
/* if success return config data length */
static int read_config_data(struct goodix_ts_device *ts_dev, void __user *arg)
{
int ret = 0;
u32 reg_addr, length;
u8 i2c_msg_head[I2C_MSG_HEAD_LEN];
u8 *tmp_buf;
ret = copy_from_user(&i2c_msg_head, arg, I2C_MSG_HEAD_LEN);
if (ret) {
ts_err("Copy data from user failed");
return -EFAULT;
}
reg_addr = i2c_msg_head[0] + (i2c_msg_head[1] << 8)
+ (i2c_msg_head[2] << 16) + (i2c_msg_head[3] << 24);
length = i2c_msg_head[4] + (i2c_msg_head[5] << 8)
+ (i2c_msg_head[6] << 16) + (i2c_msg_head[7] << 24);
ts_info("read config,reg_addr=0x%x, length=%d", reg_addr, length);
if (length > GOODIX_CFG_MAX_SIZE)
return -EMSGSIZE;
tmp_buf = kzalloc(length, GFP_KERNEL);
if (!tmp_buf) {
ts_err("failed alloc memory");
return -ENOMEM;
}
/* if reg_addr == 0, read config data with specific flow */
if (!reg_addr) {
if (ts_dev->hw_ops->read_config)
ret = ts_dev->hw_ops->read_config(ts_dev, tmp_buf, 0);
else
ret = -EINVAL;
} else {
ret = ts_dev->hw_ops->read_trans(ts_dev,
reg_addr, tmp_buf, length);
if (!ret)
ret = length;
}
if (ret <= 0)
goto err_out;
if (copy_to_user((u8 *)arg + I2C_MSG_HEAD_LEN, tmp_buf, ret)) {
ret = -EFAULT;
ts_err("Copy_to_user failed");
}
err_out:
kfree(tmp_buf);
return ret;
}
/* read data from i2c synchronous,
* success return bytes read, else return <= 0
*/
static int sync_read(struct goodix_tools_dev *dev, void __user *arg)
{
int ret = 0;
u8 i2c_msg_head[I2C_MSG_HEAD_LEN];
struct goodix_tools_data tools_data;
ret = copy_from_user(&i2c_msg_head, arg, I2C_MSG_HEAD_LEN);
if (ret) {
ts_err("Copy data from user failed");
return -EFAULT;
}
tools_data.reg_addr = i2c_msg_head[0] + (i2c_msg_head[1] << 8)
+ (i2c_msg_head[2] << 16) + (i2c_msg_head[3] << 24);
tools_data.length = i2c_msg_head[4] + (i2c_msg_head[5] << 8)
+ (i2c_msg_head[6] << 16) + (i2c_msg_head[7] << 24);
tools_data.filled = 0;
if (tools_data.length > GOODIX_CFG_MAX_SIZE)
return -EMSGSIZE;
tools_data.data = kzalloc(tools_data.length, GFP_KERNEL);
if (!tools_data.data) {
ts_err("Alloc memory failed");
return -ENOMEM;
}
mutex_lock(&dev->mutex);
list_add_tail(&tools_data.list, &dev->head);
mutex_unlock(&dev->mutex);
/* wait queue will timeout after 1 seconds */
if (!wait_event_interruptible_timeout(dev->wq,
tools_data.filled == 1, HZ * 3)) {
ret = -EAGAIN;
ts_err("Wait queue timeout");
goto err_out;
}
mutex_lock(&dev->mutex);
list_del(&tools_data.list);
mutex_unlock(&dev->mutex);
if (tools_data.filled == 1) {
if (copy_to_user((u8 *)arg + I2C_MSG_HEAD_LEN, tools_data.data,
tools_data.length)) {
ret = -EFAULT;
ts_err("Copy_to_user failed");
} else {
ret = tools_data.length;
}
} else {
ret = -EAGAIN;
ts_err("Wait queue timeout");
}
err_out:
kfree(tools_data.data);
return ret;
}
/* write data to i2c asynchronous,
* success return bytes write, else return <= 0
*/
static int async_write(struct goodix_tools_dev *dev, void __user *arg)
{
u8 *databuf;
int ret = 0;
u32 reg_addr, length;
u8 i2c_msg_head[I2C_MSG_HEAD_LEN];
struct goodix_ts_device *ts_dev = dev->ts_core->ts_dev;
const struct goodix_ts_hw_ops *hw_ops = ts_dev->hw_ops;
ret = copy_from_user(&i2c_msg_head, arg, I2C_MSG_HEAD_LEN);
if (ret) {
ts_err("Copy data from user failed");
return -EFAULT;
}
reg_addr = i2c_msg_head[0] + (i2c_msg_head[1] << 8)
+ (i2c_msg_head[2] << 16) + (i2c_msg_head[3] << 24);
length = i2c_msg_head[4] + (i2c_msg_head[5] << 8)
+ (i2c_msg_head[6] << 16) + (i2c_msg_head[7] << 24);
if (length > GOODIX_CFG_MAX_SIZE)
return -EMSGSIZE;
databuf = kzalloc(length, GFP_KERNEL);
if (!databuf) {
ts_err("Alloc memory failed");
return -ENOMEM;
}
ret = copy_from_user(databuf, (u8 *)arg + I2C_MSG_HEAD_LEN, length);
if (ret) {
ret = -EFAULT;
ts_err("Copy data from user failed");
goto err_out;
}
if (hw_ops->write_trans(ts_dev, reg_addr, databuf, length)) {
ret = -EBUSY;
ts_err("Write data to device failed");
} else {
ret = length;
}
err_out:
kfree(databuf);
return ret;
}
static int init_cfg_data(struct goodix_ts_config *cfg, void __user *arg)
{
int ret = 0;
u32 reg_addr, length;
u8 i2c_msg_head[I2C_MSG_HEAD_LEN];
cfg->initialized = 0;
mutex_init(&cfg->lock);
ret = copy_from_user(&i2c_msg_head, arg, I2C_MSG_HEAD_LEN);
if (ret) {
ts_err("Copy data from user failed");
return -EFAULT;
}
reg_addr = i2c_msg_head[0] + (i2c_msg_head[1] << 8)
+ (i2c_msg_head[2] << 16) + (i2c_msg_head[3] << 24);
length = i2c_msg_head[4] + (i2c_msg_head[5] << 8)
+ (i2c_msg_head[6] << 16) + (i2c_msg_head[7] << 24);
if (length > GOODIX_CFG_MAX_SIZE)
return -EMSGSIZE;
ret = copy_from_user(cfg->data, (u8 *)arg + I2C_MSG_HEAD_LEN, length);
if (ret) {
ret = -EFAULT;
ts_err("Copy data from user failed");
goto err_out;
}
cfg->reg_base = reg_addr;
cfg->length = length;
strlcpy(cfg->name, "tools-send-cfg", sizeof(cfg->name));
cfg->delay = 50;
cfg->initialized = true;
return 0;
err_out:
return ret;
}
/**
* goodix_tools_ioctl - ioctl implementation
*
* @filp: Pointer to file opened
* @cmd: Ioctl opertion command
* @arg: Command data
* Returns >=0 - succeed, else failed
*/
static long goodix_tools_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg)
{
int ret = 0;
struct goodix_tools_dev *dev = filp->private_data;
struct goodix_ts_device *ts_dev;
const struct goodix_ts_hw_ops *hw_ops;
struct goodix_ts_cmd temp_cmd;
struct goodix_ts_config *temp_cfg = NULL;
if (dev->ts_core == NULL) {
ts_err("Tools module not register");
return -EINVAL;
}
ts_dev = dev->ts_core->ts_dev;
hw_ops = ts_dev->hw_ops;
if (_IOC_TYPE(cmd) != GOODIX_TS_IOC_MAGIC) {
ts_err("Bad magic num:%c", _IOC_TYPE(cmd));
return -ENOTTY;
}
if (_IOC_NR(cmd) > GOODIX_TS_IOC_MAXNR) {
ts_err("Bad cmd num:%d > %d",
_IOC_NR(cmd), GOODIX_TS_IOC_MAXNR);
return -ENOTTY;
}
switch (cmd & NEGLECT_SIZE_MASK) {
case GTP_IRQ_ENABLE:
if (arg == 1) {
goodix_ts_irq_enable(dev->ts_core, true);
mutex_lock(&dev->mutex);
dev->ops_mode |= IRQ_FALG;
mutex_unlock(&dev->mutex);
ts_info("IRQ enabled");
} else if (arg == 0) {
goodix_ts_irq_enable(dev->ts_core, false);
mutex_lock(&dev->mutex);
dev->ops_mode &= ~IRQ_FALG;
mutex_unlock(&dev->mutex);
ts_info("IRQ disabled");
} else {
ts_info("Irq aready set with, arg = %ld", arg);
}
ret = 0;
break;
case GTP_ESD_ENABLE:
if (arg == 0)
goodix_ts_blocking_notify(NOTIFY_ESD_OFF, NULL);
else
goodix_ts_blocking_notify(NOTIFY_ESD_ON, NULL);
break;
case GTP_DEV_RESET:
hw_ops->reset(ts_dev);
break;
case GTP_SEND_COMMAND:
ret = copy_from_user(&temp_cmd, (void __user *)arg,
sizeof(struct goodix_ts_cmd));
if (ret) {
ret = -EINVAL;
goto err_out;
}
ret = hw_ops->send_cmd(ts_dev, &temp_cmd);
if (ret) {
ts_err("Send command failed");
ret = -EAGAIN;
}
break;
case GTP_SEND_CONFIG:
temp_cfg = kzalloc(sizeof(struct goodix_ts_config), GFP_KERNEL);
if (temp_cfg == NULL) {
ts_err("Memory allco err");
ret = -ENOMEM;
goto err_out;
}
ret = init_cfg_data(temp_cfg, (void __user *)arg);
if (!ret && hw_ops->send_config) {
ret = hw_ops->send_config(ts_dev, temp_cfg);
if (ret) {
ts_err("Failed send config");
ret = -EAGAIN;
} else {
ts_info("Send config success");
ret = 0;
}
}
break;
case GTP_READ_CONFIG:
ret = read_config_data(ts_dev, (void __user *)arg);
if (ret > 0)
ts_info("success read config:len=%d", ret);
else
ts_err("failed read config:ret=0x%x", ret);
break;
case GTP_ASYNC_READ:
ret = async_read(dev, (void __user *)arg);
if (ret < 0)
ts_err("Async data read failed");
break;
case GTP_SYNC_READ:
if (filp->f_flags & O_NONBLOCK) {
ts_err("Goodix tools now worked in sync_bus mode");
ret = -EAGAIN;
goto err_out;
}
ret = sync_read(dev, (void __user *)arg);
if (ret < 0)
ts_err("Sync data read failed");
break;
case GTP_ASYNC_WRITE:
ret = async_write(dev, (void __user *)arg);
if (ret < 0)
ts_err("Async data write failed");
break;
case GTP_DRV_VERSION:
ret = copy_to_user((u8 *)arg, GOODIX_DRIVER_VERSION,
sizeof(GOODIX_DRIVER_VERSION));
if (ret)
ts_err("failed copy driver version info to user");
break;
default:
ts_info("Invalid cmd");
ret = -ENOTTY;
break;
}
err_out:
if (!temp_cfg) {
kfree(temp_cfg);
temp_cfg = NULL;
}
return ret;
}
#ifdef CONFIG_COMPAT
static long goodix_tools_compat_ioctl(struct file *file, unsigned int cmd,
unsigned long arg)
{
void __user *arg32 = compat_ptr(arg);
if (!file->f_op || !file->f_op->unlocked_ioctl)
return -ENOTTY;
return file->f_op->unlocked_ioctl(file, cmd, (unsigned long)arg32);
}
#endif
static int goodix_tools_open(struct inode *inode, struct file *filp)
{
int ret = 0;
filp->private_data = goodix_tools_dev;
ts_info("tools open");
/* Only the first time open device need to register module */
ret = goodix_register_ext_module(&goodix_tools_dev->module);
if (ret)
ts_info("failed register to core module");
return ret;
}
static int goodix_tools_release(struct inode *inode, struct file *filp)
{
int ret = 0;
/* when the last close this dev node unregister the module */
ret = goodix_unregister_ext_module(&goodix_tools_dev->module);
return ret;
}
/**
* goodix_tools_module_irq - goodix tools Irq handle
* This functions is excuted when interrupt happended
*
* @core_data: pointer to touch core data
* @module: pointer to goodix_ext_module struct
* return: EVT_CONTINUE let other module handle this irq
*/
static int goodix_tools_module_irq(struct goodix_ts_core *core_data,
struct goodix_ext_module *module)
{
struct goodix_tools_dev *dev = module->priv_data;
struct goodix_ts_device *ts_dev = dev->ts_core->ts_dev;
const struct goodix_ts_hw_ops *hw_ops = ts_dev->hw_ops;
struct goodix_tools_data *tools_data;
int r = 0;
u8 evt_sta = 0;
mutex_lock(&dev->mutex);
if (!list_empty(&dev->head)) {
r = hw_ops->read_trans(ts_dev, ts_dev->reg.coor, &evt_sta, 1);
if (r < 0 || ((evt_sta & GOODIX_TOUCH_EVENT) == 0)) {
ts_err("data not ready:0x%x, read ret =%d", evt_sta, r);
mutex_unlock(&dev->mutex);
return EVT_CONTINUE;
}
list_for_each_entry(tools_data, &dev->head, list) {
if (!hw_ops->read_trans(ts_dev, tools_data->reg_addr,
tools_data->data, tools_data->length)) {
tools_data->filled = 1;
}
}
wake_up(&dev->wq);
}
mutex_unlock(&dev->mutex);
return EVT_CONTINUE;
}
static int goodix_tools_module_init(struct goodix_ts_core *core_data,
struct goodix_ext_module *module)
{
struct goodix_tools_dev *tools_dev = module->priv_data;
if (core_data)
tools_dev->ts_core = core_data;
else
return -ENODEV;
return 0;
}
static const struct file_operations goodix_tools_fops = {
.owner = THIS_MODULE,
.open = goodix_tools_open,
.release = goodix_tools_release,
.unlocked_ioctl = goodix_tools_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = goodix_tools_compat_ioctl,
#endif
};
static struct miscdevice goodix_tools_miscdev = {
.minor = MISC_DYNAMIC_MINOR,
.name = GOODIX_TOOLS_NAME,
.fops = &goodix_tools_fops,
};
static struct goodix_ext_module_funcs goodix_tools_module_funcs = {
.irq_event = goodix_tools_module_irq,
.init = goodix_tools_module_init,
};
/**
* goodix_tools_init - init goodix tools device and register a miscdevice
*
* return: 0 success, else failed
*/
static int __init goodix_tools_init(void)
{
int ret;
goodix_tools_dev = kzalloc(sizeof(struct goodix_tools_dev), GFP_KERNEL);
if (goodix_tools_dev == NULL) {
ts_err("Memory allco err");
return -ENOMEM;
}
INIT_LIST_HEAD(&goodix_tools_dev->head);
goodix_tools_dev->ops_mode = 0;
goodix_tools_dev->ops_mode |= IRQ_FALG;
init_waitqueue_head(&goodix_tools_dev->wq);
mutex_init(&goodix_tools_dev->mutex);
atomic_set(&goodix_tools_dev->t_count, 0);
goodix_tools_dev->module.funcs = &goodix_tools_module_funcs;
goodix_tools_dev->module.name = GOODIX_TOOLS_NAME;
goodix_tools_dev->module.priv_data = goodix_tools_dev;
goodix_tools_dev->module.priority = EXTMOD_PRIO_DBGTOOL;
ret = misc_register(&goodix_tools_miscdev);
if (ret)
ts_err("Debug tools miscdev register failed");
return ret;
}
static void __exit goodix_tools_exit(void)
{
misc_deregister(&goodix_tools_miscdev);
kfree(goodix_tools_dev);
ts_info("Goodix tools miscdev exit");
}
module_init(goodix_tools_init);
module_exit(goodix_tools_exit);
MODULE_DESCRIPTION("Goodix tools Module");
MODULE_AUTHOR("Goodix, Inc.");
MODULE_LICENSE("GPL v2");
@@ -0,0 +1,37 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifdef CONFIG_TRUSTONIC_TRUSTED_UI
#include "goodix_ts_core.h"
atomic_t gt9886_tui_flag = ATOMIC_INIT(0);
EXPORT_SYMBOL(gt9886_tui_flag);
int tpd_enter_tui(void)
{
int ret = 0;
ts_info("[%s] enter TUI", __func__);
atomic_set(&gt9886_tui_flag, true);
return ret;
}
int tpd_exit_tui(void)
{
int ret = 0;
ts_info("[%s] exit TUI", __func__);
atomic_set(&gt9886_tui_flag, false);
goodix_ts_irq_enable(resume_core_data, false);
goodix_ts_irq_enable(resume_core_data, true);
return ret;
}
#endif