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

@@ -0,0 +1,9 @@
# Goodix Touchscreen Makefile
# This Makefile is only for tempory compiling use
# Use xxxproject/Makefile-release when release driver
#
obj-y += goodix_ts_spi.o
obj-y += goodix_ts_core.o
obj-y += goodix_cfg_bin.o
obj-y += goodix_gtx8_update.o
obj-n += goodix_ts_tools.o
@@ -0,0 +1,585 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2016 MediaTek Inc.
*/
#include "goodix_cfg_bin.h"
int gt9896s_parse_cfg_bin(struct gt9896s_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 gt9896s_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 gt9896s_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 check failed,%d != %d",
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 check filed 0x%02x != 0x%02x",
cfg_bin->head.checksum, checksum);
r = -EINVAL;
goto exit;
}
/*allocate memory for cfg packages*/
cfg_bin->cfg_pkgs = kzalloc(sizeof(struct gt9896s_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, 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*/
gt9896s_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*/
ts_info("Driver bin info: ver %s, len %d, pkgs %d", cfg_bin->head.bin_version,
cfg_bin->head.bin_len, cfg_bin->head.pkg_num);
for (i = 0; i < cfg_bin->head.pkg_num; i++) {
ts_debug("---------------------------------------------");
ts_debug("------package:%d------", i + 1);
ts_debug("package len:%04x", cfg_bin->cfg_pkgs[i].cnst_info.pkg_len);
ts_debug("package ic_type:%s", cfg_bin->cfg_pkgs[i].cnst_info.ic_type);
ts_debug("package cfg_type:%01x", cfg_bin->cfg_pkgs[i].cnst_info.cfg_type);
ts_debug("package sensor_id:%01x", cfg_bin->cfg_pkgs[i].cnst_info.sensor_id);
ts_debug("package hw_pid:%s", cfg_bin->cfg_pkgs[i].cnst_info.hw_pid);
ts_debug("package hw_vid:%s", cfg_bin->cfg_pkgs[i].cnst_info.hw_vid);
ts_debug("package fw_mask_version:%s", cfg_bin->cfg_pkgs[i].cnst_info.fw_mask);
ts_debug("package fw_patch_version:%s", cfg_bin->cfg_pkgs[i].cnst_info.fw_patch);
ts_debug("package x_res_offset:%02x", cfg_bin->cfg_pkgs[i].cnst_info.x_res_offset);
ts_debug("package y_res_offset:%02x", cfg_bin->cfg_pkgs[i].cnst_info.y_res_offset);
ts_debug("package trigger_offset:%02x", cfg_bin->cfg_pkgs[i].cnst_info.trigger_offset);
ts_debug("reg info");
ts_debug("send_cfg_flag reg:%02x", cfg_bin->cfg_pkgs[i].reg_info.cfg_send_flag.addr);
ts_debug("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_debug("pid reg:%02x:%d", cfg_bin->cfg_pkgs[i].reg_info.pid.addr,
cfg_bin->cfg_pkgs[i].reg_info.pid.reserved1);
ts_debug("vid reg:%02x:%d", cfg_bin->cfg_pkgs[i].reg_info.vid.addr,
cfg_bin->cfg_pkgs[i].reg_info.vid.reserved1);
ts_debug("sensor_id reg:%02x,mask:%x", cfg_bin->cfg_pkgs[i].reg_info.sensor_id.addr,
cfg_bin->cfg_pkgs[i].reg_info.sensor_id.addr);
ts_debug("fw_status reg:%02x", cfg_bin->cfg_pkgs[i].reg_info.fw_status.addr);
ts_debug("cfg_addr reg:%02x", cfg_bin->cfg_pkgs[i].reg_info.cfg_addr.addr);
ts_debug("esd reg:%02x", cfg_bin->cfg_pkgs[i].reg_info.esd.addr);
ts_debug("command reg:%02x", cfg_bin->cfg_pkgs[i].reg_info.command.addr);
ts_debug("coor:%02x", cfg_bin->cfg_pkgs[i].reg_info.coor.addr);
ts_debug("gesture:%02x", cfg_bin->cfg_pkgs[i].reg_info.gesture.addr);
ts_debug("fw_request:%02x", cfg_bin->cfg_pkgs[i].reg_info.fw_request.addr);
ts_debug("proximity:%02x", cfg_bin->cfg_pkgs[i].reg_info.proximity.addr);
ts_debug("--------------------------------------------");
}
r = 0;
exit:
return r;
}
static int gt9896s_cfg_bin_proc(struct gt9896s_ts_core *core_data)
{
int r;
struct gt9896s_ts_device *ts_dev = core_data->ts_dev;
struct gt9896s_cfg_bin *cfg_bin = kzalloc(sizeof(struct gt9896s_cfg_bin),
GFP_KERNEL);
if (!cfg_bin) {
return -ENOMEM;
}
if (!ts_dev) {
ts_err("ts device can't be null");
goto out;
}
/* when start init config bin with error state */
ts_dev->cfg_bin_state = CFG_BIN_STATE_ERROR;
/*get cfg_bin from file system*/
r = gt9896s_read_cfg_bin(ts_dev, cfg_bin);
if (r < 0) {
ts_err("Failed get valid config bin data");
goto exit;
}
/*parse cfg bin*/
r = gt9896s_parse_cfg_bin(cfg_bin);
if (!r) {
ts_info("parse cfg bin SUCCESS");
} else {
ts_err("parse cfg bin FAILED");
goto exit;
}
/*get register address and configuration from cfg bin*/
r = gt9896s_get_reg_and_cfg(ts_dev, cfg_bin);
if (!r) {
ts_info("success get reg and cfg info from cfg bin");
} else {
ts_err("failed get cfg and reg info, update fw then retry");
}
/*debug*/
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);
exit:
kfree(cfg_bin->cfg_pkgs);
kfree(cfg_bin->bin_data);
kfree(cfg_bin);
if (r)
gt9896s_ts_blocking_notify(NOTIFY_CFG_BIN_FAILED, &r);
else
gt9896s_ts_blocking_notify(NOTIFY_CFG_BIN_SUCCESS, &r);
ts_info("cfg bin state %d, ret %d", ts_dev->cfg_bin_state, r);
return r;
out:
kfree(cfg_bin);
return -EINVAL;
}
static int gt9896s_extract_cfg_pkg(struct gt9896s_ts_device *ts_dev,
struct gt9896s_cfg_package *cfg_pkg)
{
struct gt9896s_ts_config *ts_cfg;
if (cfg_pkg->cnst_info.cfg_type == TS_NORMAL_CFG) {
ts_cfg = &(ts_dev->normal_cfg);
} else if (cfg_pkg->cnst_info.cfg_type == TS_HIGH_SENSE_CFG) {
ts_cfg = &(ts_dev->highsense_cfg);
} else {
ts_err("unknown cfg type %d", cfg_pkg->cnst_info.cfg_type);
return -EINVAL;
}
ts_cfg->length = cfg_pkg->pkg_len -
TS_PKG_CONST_INFO_LEN - TS_PKG_REG_INFO_LEN;
if (ts_cfg->length > sizeof(ts_cfg->data)) {
ts_err("illegal cfg length %d", ts_cfg->length);
return -EINVAL;
}
if (ts_cfg->length) {
ts_info("get config type %d, len %d",
cfg_pkg->cnst_info.cfg_type, ts_cfg->length);
memcpy(ts_cfg->data, cfg_pkg->cfg, ts_cfg->length);
ts_cfg->initialized = TS_CFG_STABLE;
mutex_init(&ts_cfg->lock);
} else {
ts_info("no config data");
}
/*get register info*/
ts_dev->reg.cfg_send_flag = cfg_pkg->reg_info.cfg_send_flag.addr;
ts_dev->reg.version_base = cfg_pkg->reg_info.version_base.addr;
ts_dev->reg.version_len = cfg_pkg->reg_info.version_base.reserved1;
ts_dev->reg.pid = cfg_pkg->reg_info.pid.addr;
ts_dev->reg.pid_len = cfg_pkg->reg_info.pid.reserved1;
ts_dev->reg.vid = cfg_pkg->reg_info.vid.addr;
ts_dev->reg.vid_len = cfg_pkg->reg_info.vid.reserved1;
ts_dev->reg.sensor_id = cfg_pkg->reg_info.sensor_id.addr;
ts_dev->reg.sensor_id_mask = cfg_pkg->reg_info.sensor_id.reserved1;
ts_dev->reg.fw_mask = cfg_pkg->reg_info.fw_mask.addr;
ts_dev->reg.fw_status = cfg_pkg->reg_info.fw_status.addr;
ts_dev->reg.cfg_addr = cfg_pkg->reg_info.cfg_addr.addr;
ts_dev->reg.esd = cfg_pkg->reg_info.esd.addr;
ts_dev->reg.command = cfg_pkg->reg_info.command.addr;
ts_dev->reg.coor = cfg_pkg->reg_info.coor.addr;
ts_dev->reg.gesture = cfg_pkg->reg_info.gesture.addr;
ts_dev->reg.fw_request = cfg_pkg->reg_info.fw_request.addr;
ts_dev->reg.proximity = cfg_pkg->reg_info.proximity.addr;
return 0;
}
int gt9896s_get_reg_and_cfg(struct gt9896s_ts_device *ts_dev,
struct gt9896s_cfg_bin *cfg_bin)
{
int i;
u16 addr;
u8 read_len;
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;
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);
return -EINVAL;
}
memset(&ts_dev->normal_cfg, 0, sizeof(ts_dev->normal_cfg));
memset(&ts_dev->highsense_cfg, 0, sizeof(ts_dev->highsense_cfg));
/* find 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,
"normandy", strlen("normandy"))) {
ts_dev->ic_type = IC_TYPE_NORMANDY;
} else if (!strncmp(cfg_bin->cfg_pkgs[i].cnst_info.ic_type,
"yellowstone_s", strlen("yellowstone_s"))) {
ts_dev->ic_type = IC_TYPE_YELLOWSTONE_SPI;
} else if (!strncmp(cfg_bin->cfg_pkgs[i].cnst_info.ic_type,
"yellowstone", strlen("yellowstone"))) {
ts_dev->ic_type = IC_TYPE_YELLOWSTONE;
} else {
ts_err("unknow ic type of cfg_bin:%s",
cfg_bin->cfg_pkgs[i].cnst_info.ic_type);
continue;
}
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 = ts_dev->hw_ops->read(ts_dev, addr, &temp_sensor_id, 1);
if (r < 0) {
ts_err("failed get sensor of pkg:%d, reg:0x%02x", i, addr);
goto get_default_pkg;
}
ts_info("sensor id is %d", temp_sensor_id);
/*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, reg:0x%02x",
i, addr);
ts_err("sensor_id from i2c:%d, sensor_id of cfg 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]) {
r = ts_dev->hw_ops->read(ts_dev, addr, temp_fw_mask,
sizeof(temp_fw_mask));
if (r < 0) {
ts_err("failed read fw_mask pkg:%d, reg:0x%02x",
i, addr);
goto get_default_pkg;
}
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, 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 length ERROR, len:%d",
i, read_len);
continue;
}
r = ts_dev->hw_ops->read(ts_dev, addr, temp_pid, read_len);
if (r < 0) {
ts_err("failed read pid pkg:%d, pid reg:0x%02x", i, addr);
goto get_default_pkg;
}
if (strncmp(temp_pid, cfg_bin->cfg_pkgs[i].cnst_info.hw_pid, read_len)) {
ts_err("pkg:%d, pid contrast FAILED, reg:0x%02x", i, addr);
ts_err("pid from spi:%s, pid of cfg bin:%s",
temp_pid, cfg_bin->cfg_pkgs[i].cnst_info.hw_pid);
continue;
}
ts_info("try get package info: ic type %s, cfg type %d",
cfg_bin->cfg_pkgs[i].cnst_info.ic_type,
cfg_bin->cfg_pkgs[i].cnst_info.cfg_type);
/* currently only support normal and high_sense config */
if (cfg_bin->cfg_pkgs[i].cnst_info.cfg_type == TS_NORMAL_CFG ||
cfg_bin->cfg_pkgs[i].cnst_info.cfg_type == TS_HIGH_SENSE_CFG) {
r = gt9896s_extract_cfg_pkg(ts_dev, &cfg_bin->cfg_pkgs[i]);
if (!r) {
ts_dev->cfg_bin_state = CFG_BIN_STATE_INITIALIZED;
ts_info("success parse cfg bin");
} else {
ts_err("failed parse cfg bin");
break;
}
}
}
get_default_pkg:
if (ts_dev->cfg_bin_state != CFG_BIN_STATE_INITIALIZED) {
ts_err("no valid normal cfg, use cfg_pkg 0 as default");
/* Foo code for recover dead IC.
* force set package 0 config type to normal config, this will
* config will use to recover IC.
*/
cfg_bin->cfg_pkgs[0].cnst_info.cfg_type = TS_NORMAL_CFG;
if (gt9896s_extract_cfg_pkg(ts_dev, &cfg_bin->cfg_pkgs[0])) {
ts_err("failed get valid config for IC recover");
ts_dev->cfg_bin_state = CFG_BIN_STATE_ERROR;
} else {
ts_dev->cfg_bin_state = CFG_BIN_STATE_TEMP;
ts_info("get temp config data");
}
r = -EINVAL;
}
return r;
}
int gt9896s_read_cfg_bin(struct gt9896s_ts_device *ts_dev, struct gt9896s_cfg_bin *cfg_bin)
{
const struct firmware *firmware = NULL;
struct gt9896s_ts_board_data *ts_bdata = &ts_dev->board_data;
char cfg_bin_name[64] = {0x00};
int i = 0, r;
/*get cfg_bin_name*/
if (ts_bdata->lcm_max_x == 1080 && ts_bdata->lcm_max_y == 2280) {
r = snprintf(cfg_bin_name, sizeof(cfg_bin_name), "%s%s_1080x2280.bin",
TS_DEFAULT_CFG_BIN, gt9896s_config_buf);
} else if (ts_bdata->lcm_max_x == 1080 && ts_bdata->lcm_max_y == 2300) {
r = snprintf(cfg_bin_name, sizeof(cfg_bin_name), "%s%s_1080x2300.bin",
TS_DEFAULT_CFG_BIN, gt9896s_config_buf);
} else {
r = snprintf(cfg_bin_name, sizeof(cfg_bin_name), "%s%s.bin",
TS_DEFAULT_CFG_BIN, gt9896s_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, ts_dev->dev);
if (r < 0) {
ts_err("failed get cfg bin[%s] error:%d, 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) {
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;
}
void gt9896s_cfg_pkg_leToCpu(struct gt9896s_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);
}
static int gt9896s_later_init_thread(void *data)
{
int ret;
struct gt9896s_ts_core *ts_core = data;
struct gt9896s_ts_device *ts_dev;
if (!data) {
ts_err("ts core data can't be null");
return -EINVAL;
}
ts_dev = ts_core->ts_dev;
if (!ts_dev) {
ts_err("ts dev data can't be null");
return -EINVAL;
}
ret = gt9896s_cfg_bin_proc(ts_core);
if (ret)
ts_err("parse cfg bin encounter error, %d", ret);
else
ts_info("success get cfg bin");
if (ts_dev->cfg_bin_state == CFG_BIN_STATE_ERROR) {
ts_err("parse cfg bin encounter fatal err");
goto release_core;
}
if (ts_dev->cfg_bin_state == CFG_BIN_STATE_TEMP) {
ts_err("failed get valid config data, retry after fwupdate");
ret = gt9896s_do_fw_update(UPDATE_MODE_BLOCK|UPDATE_MODE_FORCE|
UPDATE_MODE_FLASH_CFG|
UPDATE_MODE_SRC_REQUEST);
if (ret) {
ts_err("fw update failed, %d", ret);
goto release_core;
}
ts_info("fw update success retry parse cfg bin");
ret = gt9896s_cfg_bin_proc(ts_core);
if (ret) {
ts_err("failed parse cfg bin after fw update");
goto release_core;
}
} else {
ts_info("success parse config bin");
ret = gt9896s_do_fw_update(UPDATE_MODE_BLOCK|
UPDATE_MODE_FLASH_CFG|
UPDATE_MODE_SRC_REQUEST);
if (ret) {
ts_err("fw update failed, %d[ignore]", ret);
ret = 0;
}
}
ret = gt9896s_ts_stage2_init(ts_core);
if (!ret) {
ts_info("stage2 init success");
return ret;
}
ts_err("stage2 init failed, %d", ret);
release_core:
gt9896s_ts_core_release(ts_core);
return ret;
}
int gt9896s_start_later_init(struct gt9896s_ts_core *ts_core)
{
struct task_struct *init_thrd;
/* create and run update thread */
init_thrd = kthread_run(gt9896s_later_init_thread,
ts_core, "gt9896s_init_thread");
if (IS_ERR_OR_NULL(init_thrd)) {
ts_err("Failed to create update thread:%ld",
PTR_ERR(init_thrd));
return -EFAULT;
}
return 0;
}
@@ -0,0 +1,119 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2016 MediaTek Inc.
*/
#ifndef _GOODIX_CFG_BIN_H_
#define _GOODIX_CFG_BIN_H_
#include "goodix_ts_core.h"
#define TS_DEFAULT_FIRMWARE "gt9896s_firmware_"
#define TS_DEFAULT_CFG_BIN "gt9896s_cfg_"
extern const char *gt9896s_firmware_buf;
extern const char *gt9896s_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 gt9896s_cfg_bin_head) + TS_CFG_BIN_HEAD_RESERVED_LEN)
#define TS_PKG_CONST_INFO_LEN (sizeof(struct gt9896s_cfg_pkg_const_info))
#define TS_PKG_REG_INFO_LEN (sizeof(struct gt9896s_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 gt9896s_cfg_pkg_reg {
u16 addr;
u8 reserved1;
u8 reserved2;
};
struct gt9896s_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 gt9896s_cfg_pkg_reg_info {
struct gt9896s_cfg_pkg_reg cfg_send_flag;
struct gt9896s_cfg_pkg_reg version_base;
struct gt9896s_cfg_pkg_reg pid;
struct gt9896s_cfg_pkg_reg vid;
struct gt9896s_cfg_pkg_reg sensor_id;
struct gt9896s_cfg_pkg_reg fw_mask;
struct gt9896s_cfg_pkg_reg fw_status;
struct gt9896s_cfg_pkg_reg cfg_addr;
struct gt9896s_cfg_pkg_reg esd;
struct gt9896s_cfg_pkg_reg command;
struct gt9896s_cfg_pkg_reg coor;
struct gt9896s_cfg_pkg_reg gesture;
struct gt9896s_cfg_pkg_reg fw_request;
struct gt9896s_cfg_pkg_reg proximity;
u8 reserved[TS_CFG_BLOCK_RESERVED_LEN];
};
struct gt9896s_cfg_bin_head {
u32 bin_len;
u8 checksum;
u8 bin_version[TS_BIN_VERSION_LEN];
u8 pkg_num;
};
#pragma pack()
struct gt9896s_cfg_package {
struct gt9896s_cfg_pkg_const_info cnst_info;
struct gt9896s_cfg_pkg_reg_info reg_info;
const u8 *cfg;
u32 pkg_len;
};
struct gt9896s_cfg_bin {
unsigned char *bin_data;
unsigned int bin_data_len;
struct gt9896s_cfg_bin_head head;
struct gt9896s_cfg_package *cfg_pkgs;
};
extern struct gt9896s_module gt9896s_modules;
int gt9896s_ts_stage2_init(struct gt9896s_ts_core *core_data);
int gt9896s_ts_core_release(struct gt9896s_ts_core *core_data);
int gt9896s_parse_cfg_bin(struct gt9896s_cfg_bin *cfg_bin);
int gt9896s_get_reg_and_cfg(struct gt9896s_ts_device *ts_dev,
struct gt9896s_cfg_bin *cfg_bin);
// int gt9896s_read_cfg_bin(struct device *dev,
// struct gt9896s_cfg_bin *cfg_bin);
int gt9896s_read_cfg_bin(struct gt9896s_ts_device *ts_dev,
struct gt9896s_cfg_bin *cfg_bin);
void gt9896s_cfg_pkg_leToCpu(struct gt9896s_cfg_package *pkg);
#endif
@@ -0,0 +1,11 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2016 MediaTek Inc.
*/
#ifndef _GOODIX_FIRMWARE_FW_H_
#define _GOODIX_FIRMWARE_FW_H_
u8 gt9896s_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,764 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2016 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
#define GOODIX_FLASH_CONFIG_WITH_ISP 1
/* macros definition */
#define GOODIX_CORE_DRIVER_NAME "mtk-tpd"
#define GOODIX_PEN_DRIVER_NAME "goodix_ts,pen"
#define GOODIX_DRIVER_VERSION "v1.4.4.0"
#define GOODIX_BUS_RETRY_TIMES 3
#define GOODIX_MAX_TOUCH 10
#define GOODIX_CFG_MAX_SIZE 3072
#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 IC_TYPE_YELLOWSTONE 3
#define IC_TYPE_YELLOWSTONE_SPI 4
#define PINCTRL_STATE_SPI_DEFAULT "gt9896s_spi_mode"
#define PINCTRL_STATE_INT_ACTIVE "gt9896s_int_active"
#define PINCTRL_STATE_RST_ACTIVE "gt9896s_reset_active"
#define PINCTRL_STATE_INT_SUSPEND "gt9896s_int_suspend"
#define PINCTRL_STATE_RST_SUSPEND "gt9896s_reset_suspend"
#define GOODIX_TOUCH_EVENT 0x80
#define GOODIX_REQUEST_EVENT 0x40
#define GOODIX_GESTURE_EVENT 0x20
#define GOODIX_HOTKNOT_EVENT 0x10
#define GOODIX_PEN_MAX_PRESSURE 4096
#define GOODIX_MAX_TP_KEY 4
#define GOODIX_MAX_PEN_KEY 2
/*
* struct goodix_module - external modules container
* @head: external modules list
* @initilized: whether this struct is initilized
* @mutex: mutex lock
* @count: current number of registered external module
* @wq: workqueue to do register work
* @core_data: core_data pointer
*/
struct gt9896s_module {
struct list_head head;
bool initilized;
struct mutex mutex;
unsigned int count;
struct workqueue_struct *wq;
struct completion core_comp;
struct gt9896s_ts_core *core_data;
};
/*
* struct gt9896s_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_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 gt9896s_ts_board_data {
char avdd_name[24];
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 lcm_max_x;
unsigned int lcm_max_y;
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_TP_KEY];
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;
};
enum gt9896s_fw_update_mode {
UPDATE_MODE_DEFAULT = 0,
UPDATE_MODE_FORCE = (1<<0), /* force update mode */
UPDATE_MODE_BLOCK = (1<<1), /* update in block mode */
UPDATE_MODE_FLASH_CFG = (1<<2), /* reflash config */
UPDATE_MODE_SRC_SYSFS = (1<<4), /* firmware file from sysfs */
UPDATE_MODE_SRC_HEAD = (1<<5), /* firmware file from head file */
UPDATE_MODE_SRC_REQUEST = (1<<6), /* request firmware */
UPDATE_MODE_SRC_ARGS = (1<<7), /* firmware data from function args */
};
enum gt9896s_cfg_init_state {
TS_CFG_UNINITALIZED,
TS_CFG_STABLE,
TS_CFG_TEMP,
};
/*
* struct gt9896s_ts_config - chip config data
* @initialized: cfg init state, 0 uninit,
* 1 init with stable config, 2 init with temp config.
* @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 gt9896s_ts_config {
int 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 gt9896s_ts_cmd - command package
* @initialized: whether initialized
* @cmd_reg: command register
* @length: command length in bytes
* @cmds: command data
*/
#pragma pack(4)
struct gt9896s_ts_cmd {
u32 initialized;
u32 cmd_reg;
u32 length;
u8 cmds[8];
};
#pragma pack()
/* interrupt event type */
enum ts_event_type {
EVENT_INVALID = 0,
EVENT_TOUCH = (1 << 0), /* finger touch event */
EVENT_PEN = (1 << 1), /* pen event */
EVENT_REQUEST = (1 << 2),
};
/* 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_FAILED,
NOTIFY_FWUPDATE_SUCCESS,
NOTIFY_SUSPEND,
NOTIFY_RESUME,
NOTIFY_ESD_OFF,
NOTIFY_ESD_ON,
NOTIFY_CFG_BIN_FAILED,
NOTIFY_CFG_BIN_SUCCESS,
};
enum touch_point_status {
TS_NONE,
TS_RELEASE,
TS_TOUCH,
};
/* coordinate package */
struct gt9896s_ts_coords {
int status; /* NONE, RELEASE, TOUCH */
unsigned int x, y, w, p;
};
struct gt9896s_pen_coords {
int status; /* NONE, RELEASE, TOUCH */
int tool_type; /* BTN_TOOL_RUBBER BTN_TOOL_PEN */
unsigned int x, y, p;
signed char tilt_x;
signed char tilt_y;
};
struct gt9896s_ts_key {
int status;
int code;
};
/* touch event data */
struct gt9896s_touch_data {
int touch_num;
struct gt9896s_ts_coords coords[GOODIX_MAX_TOUCH];
struct gt9896s_ts_key keys[GOODIX_MAX_TP_KEY];
};
struct gt9896s_pen_data {
struct gt9896s_pen_coords coords;
struct gt9896s_ts_key keys[GOODIX_MAX_PEN_KEY];
};
/*
* struct gt9896s_ts_event - touch event struct
* @event_type: touch event type, touch data or
* request event
* @event_data: event data
*/
struct gt9896s_ts_event {
enum ts_event_type event_type;
struct gt9896s_touch_data touch_data;
struct gt9896s_pen_data pen_data;
};
/*
* struct gt9896s_ts_version - firmware version
* @valid: whether these infomation is valid
* @pid: product id string
* @vid: firmware version code
* @cid: customer id code
* @sensor_id: sendor id
*/
struct gt9896s_ts_version {
bool valid;
char pid[GOODIX_PID_MAX_LEN];
char vid[GOODIX_VID_MAX_LEN];
u8 cid;
u8 sensor_id;
};
struct gt9896s_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;
};
enum gt9896s_cfg_bin_state {
CFG_BIN_STATE_UNINIT, /* config bin uninit */
CFG_BIN_STATE_ERROR, /* config bin encounter fatal error */
CFG_BIN_STATE_INITIALIZED, /* config bin init success */
CFG_BIN_STATE_TEMP, /* config bin need reparse */
};
/*
* struct gt9896s_ts_device - ts device data
* @name: device name
* @version: reserved
* @bus_type: i2c or spi
* @ic_type: normandy or yellowstone
* @cfg_bin_state: see enum gt9896s_cfg_bin_state
* @fw_uptodate: set to 1 after do fw update
* @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 infomation
* @sleep_cmd: sleep commang
* @gesture_cmd: gesture command
* @dev: device pointer,may be a i2c or spi device
* @of_node: device node
*/
struct gt9896s_ts_device {
char *name;
int version;
int bus_type;
int ic_type;
int cfg_bin_state;
struct gt9896s_ts_regs reg;
struct gt9896s_ts_board_data board_data;
struct gt9896s_ts_config normal_cfg;
struct gt9896s_ts_config highsense_cfg;
const struct gt9896s_ts_hw_ops *hw_ops;
struct gt9896s_ts_version chip_version;
struct device *dev;
struct spi_device *spi_dev;
char *tx_buff;
char *rx_buff;
};
/*
* struct gt9896s_ts_hw_ops - hardware opeartions
* @dev_prepare: ic prepare
* @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 gt9896s_ts_hw_ops {
int (*init)(struct gt9896s_ts_device *dev);
int (*dev_prepare)(struct gt9896s_ts_device *ts_dev);
int (*reset)(struct gt9896s_ts_device *dev);
int (*read)(struct gt9896s_ts_device *dev, unsigned int addr,
unsigned char *data, unsigned int len);
int (*write)(struct gt9896s_ts_device *dev, unsigned int addr,
unsigned char *data, unsigned int len);
int (*read_trans)(struct gt9896s_ts_device *dev, unsigned int addr,
unsigned char *data, unsigned int len);
int (*write_trans)(struct gt9896s_ts_device *dev, unsigned int addr,
unsigned char *data, unsigned int len);
int (*send_cmd)(struct gt9896s_ts_device *dev, struct gt9896s_ts_cmd *cmd);
int (*send_config)(struct gt9896s_ts_device *dev,
struct gt9896s_ts_config *config);
int (*read_config)(struct gt9896s_ts_device *dev, u8 *config_data);
int (*read_version)(struct gt9896s_ts_device *dev,
struct gt9896s_ts_version *version);
int (*event_handler)(struct gt9896s_ts_device *dev,
struct gt9896s_ts_event *ts_event);
int (*check_hw)(struct gt9896s_ts_device *dev);
int (*suspend)(struct gt9896s_ts_device *dev);
int (*resume)(struct gt9896s_ts_device *dev);
};
/*
* struct gt9896s_ts_esd - esd protector structure
* @esd_work: esd delayed work
* @esd_on: 1 - turn on esd protection, 0 - turn
* off esd protection
*/
struct gt9896s_ts_esd {
struct delayed_work esd_work;
struct notifier_block esd_notifier;
struct gt9896s_ts_core *ts_core;
atomic_t esd_on;
};
/*
* struct godix_ts_core - core layer data struct
* @initialized: indicate core state, 1 ok, 0 bad
* @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 gt9896s_ts_core {
int initialized;
struct platform_device *pdev;
struct gt9896s_ts_device *ts_dev;
struct input_dev *input_dev;
struct input_dev *pen_dev;
struct regulator *avdd;
#ifdef CONFIG_PINCTRL
struct pinctrl *pinctrl;
struct pinctrl_state *pin_spi_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 gt9896s_ts_event ts_event;
int power_on;
int irq;
size_t irq_trig_cnt;
atomic_t irq_enabled;
atomic_t suspended;
struct notifier_block ts_notifier;
struct gt9896s_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 gt9896s_ext_priority {
EXTMOD_PRIO_RESERVED = 0,
EXTMOD_PRIO_FWUPDATE,
EXTMOD_PRIO_GESTURE,
EXTMOD_PRIO_HOTKNOT,
EXTMOD_PRIO_DBGTOOL,
EXTMOD_PRIO_DEFAULT,
};
struct gt9896s_ext_module;
/* external module's operations callback */
struct gt9896s_ext_module_funcs {
int (*init)(struct gt9896s_ts_core *core_data,
struct gt9896s_ext_module *module);
int (*exit)(struct gt9896s_ts_core *core_data,
struct gt9896s_ext_module *module);
int (*before_reset)(struct gt9896s_ts_core *core_data,
struct gt9896s_ext_module *module);
int (*after_reset)(struct gt9896s_ts_core *core_data,
struct gt9896s_ext_module *module);
int (*before_suspend)(struct gt9896s_ts_core *core_data,
struct gt9896s_ext_module *module);
int (*after_suspend)(struct gt9896s_ts_core *core_data,
struct gt9896s_ext_module *module);
int (*before_resume)(struct gt9896s_ts_core *core_data,
struct gt9896s_ext_module *module);
int (*after_resume)(struct gt9896s_ts_core *core_data,
struct gt9896s_ext_module *module);
int (*irq_event)(struct gt9896s_ts_core *core_data,
struct gt9896s_ext_module *module);
};
/*
* struct gt9896s_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 gt9896s_ext_module {
struct list_head list;
char *name;
enum gt9896s_ext_priority priority;
const struct gt9896s_ext_module_funcs *funcs;
void *priv_data;
struct kobject kobj;
struct work_struct work;
};
/*
* struct gt9896s_ext_attribute - exteranl attribute struct
* @attr: attribute
* @show: show interface of external attribute
* @store: store interface of external attribute
*/
struct gt9896s_ext_attribute {
struct attribute attr;
ssize_t (*show)(struct gt9896s_ext_module *, char *);
ssize_t (*store)(struct gt9896s_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 gt9896s_ext_attribute ext_attr_##_name = \
__EXTMOD_ATTR(_name, _mode, _show, _store);
/*
* get board data pointer
*/
static inline struct gt9896s_ts_board_data *board_data(
struct gt9896s_ts_core *core)
{
if (!core || !core->ts_dev)
return NULL;
return &(core->ts_dev->board_data);
}
/*
* get touch device pointer
*/
static inline struct gt9896s_ts_device *ts_device(
struct gt9896s_ts_core *core)
{
if (!core)
return NULL;
return core->ts_dev;
}
/*
* get touch hardware operations pointer
*/
static inline const struct gt9896s_ts_hw_ops *ts_hw_ops(
struct gt9896s_ts_core *core)
{
if (!core || !core->ts_dev)
return NULL;
return core->ts_dev->hw_ops;
}
/*
* checksum helper functions
* checksum can be u8/le16/be16/le32/be32 format
* NOTE: the caller shoule 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;
}
/* cal u8 data checksum for yellowston */
static inline u16 checksum_u8_ys(u8 *data, u32 size)
{
u16 checksum = 0;
u32 i;
for (i = 0; i < size - 2; i++)
checksum += data[i];
return checksum - (data[size - 2] << 8 | data[size - 1]);
}
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 @gt9896s_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. gt9896s_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
//#define CONFIG_GOODIX_DEBUG
/* log macro */
#define ts_info(fmt, arg...) pr_info("[GT9896s-INF][%s:%d] "fmt"\n", __func__, __LINE__, ##arg)
#define ts_err(fmt, arg...) pr_info("[GT9896s-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("[GT9896s-DBG][%s:%d] "fmt"\n", __func__, __LINE__, ##arg)
#else
#define ts_debug(fmt, arg...) do {} while (0)
#endif
/**
* gt9896s_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 gt9896s_register_ext_module(struct gt9896s_ext_module *module);
/**
* gt9896s_unregister_ext_module - interface for external module
* to unregister external modules
*
* @module: pointer to external module
* return: 0 ok, <0 failed
*/
int gt9896s_unregister_ext_module(struct gt9896s_ext_module *module);
/**
* gt9896s_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 gt9896s_ts_irq_enable(struct gt9896s_ts_core *core_data, bool enable);
struct kobj_type *gt9896s_get_default_ktype(void);
/**
* fb_notifier_call_chain - notify clients of fb_events
* see enum ts_notify_event in gt9896s_ts_core.h
*/
int gt9896s_ts_blocking_notify(enum ts_notify_event evt, void *v);
/**
* * gt9896s_ts_power_on - Turn on power to the touch device
* * @core_data: pointer to touch core data
* * return: 0 ok, <0 failed
* */
int gt9896s_ts_power_on(struct gt9896s_ts_core *core_data);
/**
* gt9896s_ts_power_off - Turn off power to the touch device
* @core_data: pointer to touch core data
* return: 0 ok, <0 failed
*/
int gt9896s_ts_power_off(struct gt9896s_ts_core *core_data);
int gt9896s_ts_irq_setup(struct gt9896s_ts_core *core_data);
int gt9896s_ts_esd_init(struct gt9896s_ts_core *core);
int gt9896s_ts_register_notifier(struct notifier_block *nb);
int gt9896s_ts_fb_notifier_callback(struct notifier_block *self,
unsigned long event, void *data);
void gt9896s_msg_printf(const char *fmt, ...);
int gt9896s_do_fw_update(int mode);
int gt9896s_ts_remove(struct platform_device *pdev);
int gt9896s_start_later_init(struct gt9896s_ts_core *ts_core);
void gt9896s_ts_dev_release(void);
int gt9896s_ts_core_init(void);
#endif
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,605 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2016 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 gt9896s_tools_data - gt9896s 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 gt9896s_tools_data struct into a list
*/
struct gt9896s_tools_data {
u32 reg_addr;
u32 length;
u8 *data;
bool filled;
struct list_head list;
};
/*
* struct gt9896s_tools_dev - gt9896s 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 gt9896s_tools_dev
*/
struct gt9896s_tools_dev {
struct gt9896s_ts_core *ts_core;
struct list_head head;
unsigned int ops_mode;
struct gt9896s_ts_cmd rawdiffcmd, normalcmd;
wait_queue_head_t wq;
struct mutex mutex;
atomic_t t_count;
struct gt9896s_ext_module module;
} *gt9896s_tools_dev;
/* read data from i2c asynchronous,
* success return bytes read, else return <= 0
*/
static int async_read(struct gt9896s_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 gt9896s_ts_device *ts_dev = dev->ts_core->ts_dev;
const struct gt9896s_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);
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 gt9896s_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);
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);
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 gt9896s_tools_dev *dev, void __user *arg)
{
int ret = 0;
u8 i2c_msg_head[I2C_MSG_HEAD_LEN];
struct gt9896s_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;
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 */
wait_event_interruptible_timeout(dev->wq, tools_data.filled == 1, HZ * 3);
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");
}
kfree(tools_data.data);
return ret;
}
/* write data to i2c asynchronous,
* success return bytes write, else return <= 0
*/
static int async_write(struct gt9896s_tools_dev *dev, void __user *arg)
{
u8 *databuf;
int ret = 0;
u32 reg_addr, length;
u8 i2c_msg_head[I2C_MSG_HEAD_LEN];
struct gt9896s_ts_device *ts_dev = dev->ts_core->ts_dev;
const struct gt9896s_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);
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 gt9896s_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);
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;
}
/**
* gt9896s_tools_ioctl - ioctl implementation
*
* @filp: Pointer to file opened
* @cmd: Ioctl opertion command
* @arg: Command data
* Returns >=0 - succeed, else failed
*/
static long gt9896s_tools_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg)
{
int ret = 0;
struct gt9896s_tools_dev *dev = filp->private_data;
struct gt9896s_ts_device *ts_dev;
const struct gt9896s_ts_hw_ops *hw_ops;
struct gt9896s_ts_cmd temp_cmd;
struct gt9896s_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) {
gt9896s_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) {
gt9896s_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)
gt9896s_ts_blocking_notify(NOTIFY_ESD_OFF, NULL);
else
gt9896s_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 gt9896s_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 gt9896s_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 gt9896s_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 gt9896s_tools_open(struct inode *inode, struct file *filp)
{
int ret = 0;
filp->private_data = gt9896s_tools_dev;
ts_info("tools open");
/* Only the first time open device need to register module */
ret = gt9896s_register_ext_module(&gt9896s_tools_dev->module);
if (ret) {
ts_info("failed register to core module");
}
return ret;
}
static int gt9896s_tools_release(struct inode *inode, struct file *filp)
{
int ret = 0;
/* when the last close this dev node unregister the module */
ret = gt9896s_unregister_ext_module(&gt9896s_tools_dev->module);
return ret;
}
/**
* gt9896s_tools_module_irq - gt9896s tools Irq handle
* This functions is excuted when interrupt happended
*
* @core_data: pointer to touch core data
* @module: pointer to gt9896s_ext_module struct
* return: EVT_CONTINUE let other module handle this irq
*/
static int gt9896s_tools_module_irq(struct gt9896s_ts_core *core_data,
struct gt9896s_ext_module *module)
{
struct gt9896s_tools_dev *dev = module->priv_data;
struct gt9896s_ts_device *ts_dev = dev->ts_core->ts_dev;
const struct gt9896s_ts_hw_ops *hw_ops = ts_dev->hw_ops;
struct gt9896s_tools_data *tools_data, *next;
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/* TS_REG_COORDS_BASE*/, &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_safe(tools_data, next, &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 gt9896s_tools_module_init(struct gt9896s_ts_core *core_data,
struct gt9896s_ext_module *module)
{
struct gt9896s_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 gt9896s_tools_fops = {
.owner = THIS_MODULE,
.open = gt9896s_tools_open,
.release = gt9896s_tools_release,
.unlocked_ioctl = gt9896s_tools_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = gt9896s_tools_compat_ioctl,
#endif
};
static struct miscdevice gt9896s_tools_miscdev = {
.minor = MISC_DYNAMIC_MINOR,
.name = GOODIX_TOOLS_NAME,
.fops = &gt9896s_tools_fops,
};
static struct gt9896s_ext_module_funcs gt9896s_tools_module_funcs = {
.irq_event = gt9896s_tools_module_irq,
.init = gt9896s_tools_module_init,
};
/**
* gt9896s_tools_init - init gt9896s tools device and register a miscdevice
*
* return: 0 success, else failed
*/
static int __init gt9896s_tools_init(void)
{
int ret;
gt9896s_tools_dev =
kzalloc(sizeof(struct gt9896s_tools_dev), GFP_KERNEL);
if (gt9896s_tools_dev == NULL) {
ts_err("Memory allco err");
return -ENOMEM;
}
INIT_LIST_HEAD(&gt9896s_tools_dev->head);
gt9896s_tools_dev->ops_mode = 0;
gt9896s_tools_dev->ops_mode |= IRQ_FALG;
init_waitqueue_head(&gt9896s_tools_dev->wq);
mutex_init(&gt9896s_tools_dev->mutex);
atomic_set(&gt9896s_tools_dev->t_count, 0);
gt9896s_tools_dev->module.funcs = &gt9896s_tools_module_funcs;
gt9896s_tools_dev->module.name = GOODIX_TOOLS_NAME;
gt9896s_tools_dev->module.priv_data = gt9896s_tools_dev;
gt9896s_tools_dev->module.priority = EXTMOD_PRIO_DBGTOOL;
ret = misc_register(&gt9896s_tools_miscdev);
if (ret)
ts_err("Debug tools miscdev register failed");
return ret;
}
static void __exit gt9896s_tools_exit(void)
{
misc_deregister(&gt9896s_tools_miscdev);
kfree(gt9896s_tools_dev);
ts_info("Goodix tools miscdev exit");
}
module_init(gt9896s_tools_init);
module_exit(gt9896s_tools_exit);
MODULE_DESCRIPTION("Goodix tools Module");
MODULE_AUTHOR("Goodix, Inc.");
MODULE_LICENSE("GPL v2");