kernel_samsung_a34x-permissive/drivers/input/touchscreen/NT36672C/nt36xxx_ext_proc.c

581 lines
14 KiB
C
Raw Normal View History

/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2016 MediaTek Inc.
*/
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include "nt36xxx.h"
#if NVT_TOUCH_EXT_PROC
#define NVT_FW_VERSION "nvt_fw_version"
#define NVT_BASELINE "nvt_baseline"
#define NVT_RAW "nvt_raw"
#define NVT_DIFF "nvt_diff"
#define BUS_TRANSFER_LENGTH 256
#define NORMAL_MODE 0x00
#define TEST_MODE_1 0x21
#define TEST_MODE_2 0x22
#define HANDSHAKING_HOST_READY 0xBB
#define XDATA_SECTOR_SIZE 256
static uint8_t xdata_tmp[2048] = { 0 };
static int32_t xdata[2048] = { 0 };
static struct proc_dir_entry *NVT_proc_fw_version_entry;
static struct proc_dir_entry *NVT_proc_baseline_entry;
static struct proc_dir_entry *NVT_proc_raw_entry;
static struct proc_dir_entry *NVT_proc_diff_entry;
/*******************************************************
Description:
Novatek touchscreen change mode function.
return:
n.a.
*******************************************************/
void nvt_change_mode(uint8_t mode)
{
uint8_t buf[8] = { 0 };
//---set xdata index to EVENT BUF ADDR---
nvt_set_page(ts->mmap->EVENT_BUF_ADDR | EVENT_MAP_HOST_CMD);
//---set mode---
buf[0] = EVENT_MAP_HOST_CMD;
buf[1] = mode;
CTP_SPI_WRITE(ts->client, buf, 2);
if (mode == NORMAL_MODE) {
buf[0] = EVENT_MAP_HANDSHAKING_or_SUB_CMD_BYTE;
buf[1] = HANDSHAKING_HOST_READY;
CTP_SPI_WRITE(ts->client, buf, 2);
msleep(20);
}
}
/*******************************************************
Description:
Novatek touchscreen get firmware pipe function.
return:
Executive outcomes. 0---pipe 0. 1---pipe 1.
*******************************************************/
uint8_t nvt_get_fw_pipe(void)
{
uint8_t buf[8] = { 0 };
//---set xdata index to EVENT BUF ADDR---
nvt_set_page(ts->mmap->EVENT_BUF_ADDR | EVENT_MAP_HANDSHAKING_or_SUB_CMD_BYTE);
//---read fw status---
buf[0] = EVENT_MAP_HANDSHAKING_or_SUB_CMD_BYTE;
buf[1] = 0x00;
CTP_SPI_READ(ts->client, buf, 2);
//NVT_LOG("FW pipe=%d, buf[1]=0x%02X\n", (buf[1]&0x01), buf[1]);
return (buf[1] & 0x01);
}
/*******************************************************
Description:
Novatek touchscreen read meta data function.
return:
n.a.
*******************************************************/
void nvt_read_mdata(uint32_t xdata_addr, uint32_t xdata_btn_addr)
{
int32_t i = 0;
int32_t j = 0;
int32_t k = 0;
uint8_t buf[BUS_TRANSFER_LENGTH + 1] = { 0 };
uint32_t head_addr = 0;
int32_t dummy_len = 0;
int32_t data_len = 0;
int32_t residual_len = 0;
//---set xdata sector address & length---
head_addr = xdata_addr - (xdata_addr % XDATA_SECTOR_SIZE);
dummy_len = xdata_addr - head_addr;
data_len = ts->x_num * ts->y_num * 2;
residual_len = (head_addr + dummy_len + data_len) % XDATA_SECTOR_SIZE;
//read xdata : step 1
for (i = 0; i < ((dummy_len + data_len) / XDATA_SECTOR_SIZE); i++) {
//---change xdata index---
nvt_set_page(head_addr + XDATA_SECTOR_SIZE * i);
//---read xdata by BUS_TRANSFER_LENGTH
for (j = 0; j < (XDATA_SECTOR_SIZE / BUS_TRANSFER_LENGTH); j++) {
//---read data---
buf[0] = BUS_TRANSFER_LENGTH * j;
CTP_SPI_READ(ts->client, buf, BUS_TRANSFER_LENGTH + 1);
//---copy buf to xdata_tmp---
for (k = 0; k < BUS_TRANSFER_LENGTH; k++) {
xdata_tmp[XDATA_SECTOR_SIZE * i + BUS_TRANSFER_LENGTH * j + k] =
buf[k + 1];
}
}
}
//read xdata : step2
if (residual_len != 0) {
//---change xdata index---
nvt_set_page(xdata_addr + data_len - residual_len);
//---read xdata by BUS_TRANSFER_LENGTH
for (j = 0; j < (residual_len / BUS_TRANSFER_LENGTH + 1); j++) {
//---read data---
buf[0] = BUS_TRANSFER_LENGTH * j;
CTP_SPI_READ(ts->client, buf, BUS_TRANSFER_LENGTH + 1);
//---copy buf to xdata_tmp---
for (k = 0; k < BUS_TRANSFER_LENGTH; k++) {
xdata_tmp[(dummy_len + data_len - residual_len) +
BUS_TRANSFER_LENGTH * j + k] = buf[k + 1];
}
}
}
//---remove dummy data and 2bytes-to-1data---
for (i = 0; i < (data_len / 2); i++) {
xdata[i] =
(int16_t) (xdata_tmp[dummy_len + i * 2] +
256 * xdata_tmp[dummy_len + i * 2 + 1]);
}
#if TOUCH_KEY_NUM > 0
//read button xdata : step3
//---change xdata index---
nvt_set_page(xdata_btn_addr);
//---read data---
buf[0] = (xdata_btn_addr & 0xFF);
CTP_SPI_READ(ts->client, buf, (TOUCH_KEY_NUM * 2 + 1));
//---2bytes-to-1data---
for (i = 0; i < TOUCH_KEY_NUM; i++) {
xdata[ts->x_num * ts->y_num + i] =
(int16_t) (buf[1 + i * 2] + 256 * buf[1 + i * 2 + 1]);
}
#endif
//---set xdata index to EVENT BUF ADDR---
nvt_set_page(ts->mmap->EVENT_BUF_ADDR);
}
/*******************************************************
Description:
Novatek touchscreen get meta data function.
return:
n.a.
*******************************************************/
void nvt_get_mdata(int32_t *buf, uint8_t *m_x_num, uint8_t *m_y_num)
{
*m_x_num = ts->x_num;
*m_y_num = ts->y_num;
memcpy(buf, xdata, ((ts->x_num * ts->y_num + TOUCH_KEY_NUM) * sizeof(int32_t)));
}
/*******************************************************
Description:
Novatek touchscreen firmware version show function.
return:
Executive outcomes. 0---succeed.
*******************************************************/
static int32_t c_fw_version_show(struct seq_file *m, void *v)
{
seq_printf(m, "fw_ver=%d, x_num=%d, y_num=%d, button_num=%d\n", ts->fw_ver, ts->x_num,
ts->y_num, ts->max_button_num);
return 0;
}
/*******************************************************
Description:
Novatek touchscreen xdata sequence print show
function.
return:
Executive outcomes. 0---succeed.
*******************************************************/
static int32_t c_show(struct seq_file *m, void *v)
{
int32_t i = 0;
int32_t j = 0;
for (i = 0; i < ts->y_num; i++) {
for (j = 0; j < ts->x_num; j++) {
seq_printf(m, "%5d, ", xdata[i * ts->x_num + j]);
}
seq_puts(m, "\n");
}
#if TOUCH_KEY_NUM > 0
for (i = 0; i < TOUCH_KEY_NUM; i++) {
seq_printf(m, "%5d, ", xdata[ts->x_num * ts->y_num + i]);
}
seq_puts(m, "\n");
#endif
seq_printf(m, "\n\n");
return 0;
}
/*******************************************************
Description:
Novatek touchscreen xdata sequence print start
function.
return:
Executive outcomes. 1---call next function.
NULL---not call next function and sequence loop
stop.
*******************************************************/
static void *c_start(struct seq_file *m, loff_t *pos)
{
return *pos < 1 ? (void *)1 : NULL;
}
/*******************************************************
Description:
Novatek touchscreen xdata sequence print next
function.
return:
Executive outcomes. NULL---no next and call sequence
stop function.
*******************************************************/
static void *c_next(struct seq_file *m, void *v, loff_t *pos)
{
++*pos;
return NULL;
}
/*******************************************************
Description:
Novatek touchscreen xdata sequence print stop
function.
return:
n.a.
*******************************************************/
static void c_stop(struct seq_file *m, void *v)
{
return;
}
const struct seq_operations nvt_fw_version_seq_ops = {
.start = c_start,
.next = c_next,
.stop = c_stop,
.show = c_fw_version_show
};
const struct seq_operations nvt_seq_ops = {
.start = c_start,
.next = c_next,
.stop = c_stop,
.show = c_show
};
/*******************************************************
Description:
Novatek touchscreen /proc/nvt_fw_version open
function.
return:
n.a.
*******************************************************/
static int32_t nvt_fw_version_open(struct inode *inode, struct file *file)
{
if (mutex_lock_interruptible(&ts->lock)) {
return -ERESTARTSYS;
}
NVT_LOG("++\n");
#if NVT_TOUCH_ESD_PROTECT
nvt_esd_check_enable(false);
#endif /* #if NVT_TOUCH_ESD_PROTECT */
if (nvt_get_fw_info()) {
mutex_unlock(&ts->lock);
return -EAGAIN;
}
mutex_unlock(&ts->lock);
NVT_LOG("--\n");
return seq_open(file, &nvt_fw_version_seq_ops);
}
static const struct file_operations nvt_fw_version_fops = {
.owner = THIS_MODULE,
.open = nvt_fw_version_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
/*******************************************************
Description:
Novatek touchscreen /proc/nvt_baseline open function.
return:
Executive outcomes. 0---succeed.
*******************************************************/
static int32_t nvt_baseline_open(struct inode *inode, struct file *file)
{
if (mutex_lock_interruptible(&ts->lock)) {
return -ERESTARTSYS;
}
NVT_LOG("++\n");
#if NVT_TOUCH_ESD_PROTECT
nvt_esd_check_enable(false);
#endif /* #if NVT_TOUCH_ESD_PROTECT */
if (nvt_clear_fw_status()) {
mutex_unlock(&ts->lock);
return -EAGAIN;
}
nvt_change_mode(TEST_MODE_2);
if (nvt_check_fw_status()) {
mutex_unlock(&ts->lock);
return -EAGAIN;
}
if (nvt_get_fw_info()) {
mutex_unlock(&ts->lock);
return -EAGAIN;
}
nvt_read_mdata(ts->mmap->BASELINE_ADDR, ts->mmap->BASELINE_BTN_ADDR);
nvt_change_mode(NORMAL_MODE);
mutex_unlock(&ts->lock);
NVT_LOG("--\n");
return seq_open(file, &nvt_seq_ops);
}
static const struct file_operations nvt_baseline_fops = {
.owner = THIS_MODULE,
.open = nvt_baseline_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
/*******************************************************
Description:
Novatek touchscreen /proc/nvt_raw open function.
return:
Executive outcomes. 0---succeed.
*******************************************************/
static int32_t nvt_raw_open(struct inode *inode, struct file *file)
{
if (mutex_lock_interruptible(&ts->lock)) {
return -ERESTARTSYS;
}
NVT_LOG("++\n");
#if NVT_TOUCH_ESD_PROTECT
nvt_esd_check_enable(false);
#endif /* #if NVT_TOUCH_ESD_PROTECT */
if (nvt_clear_fw_status()) {
mutex_unlock(&ts->lock);
return -EAGAIN;
}
nvt_change_mode(TEST_MODE_2);
if (nvt_check_fw_status()) {
mutex_unlock(&ts->lock);
return -EAGAIN;
}
if (nvt_get_fw_info()) {
mutex_unlock(&ts->lock);
return -EAGAIN;
}
if (nvt_get_fw_pipe() == 0)
nvt_read_mdata(ts->mmap->RAW_PIPE0_ADDR, ts->mmap->RAW_BTN_PIPE0_ADDR);
else
nvt_read_mdata(ts->mmap->RAW_PIPE1_ADDR, ts->mmap->RAW_BTN_PIPE1_ADDR);
nvt_change_mode(NORMAL_MODE);
mutex_unlock(&ts->lock);
NVT_LOG("--\n");
return seq_open(file, &nvt_seq_ops);
}
static const struct file_operations nvt_raw_fops = {
.owner = THIS_MODULE,
.open = nvt_raw_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
/*******************************************************
Description:
Novatek touchscreen /proc/nvt_diff open function.
return:
Executive outcomes. 0---succeed. negative---failed.
*******************************************************/
static int32_t nvt_diff_open(struct inode *inode, struct file *file)
{
if (mutex_lock_interruptible(&ts->lock)) {
return -ERESTARTSYS;
}
NVT_LOG("++\n");
#if NVT_TOUCH_ESD_PROTECT
nvt_esd_check_enable(false);
#endif /* #if NVT_TOUCH_ESD_PROTECT */
if (nvt_clear_fw_status()) {
mutex_unlock(&ts->lock);
return -EAGAIN;
}
nvt_change_mode(TEST_MODE_2);
if (nvt_check_fw_status()) {
mutex_unlock(&ts->lock);
return -EAGAIN;
}
if (nvt_get_fw_info()) {
mutex_unlock(&ts->lock);
return -EAGAIN;
}
if (nvt_get_fw_pipe() == 0)
nvt_read_mdata(ts->mmap->DIFF_PIPE0_ADDR, ts->mmap->DIFF_BTN_PIPE0_ADDR);
else
nvt_read_mdata(ts->mmap->DIFF_PIPE1_ADDR, ts->mmap->DIFF_BTN_PIPE1_ADDR);
nvt_change_mode(NORMAL_MODE);
mutex_unlock(&ts->lock);
NVT_LOG("--\n");
return seq_open(file, &nvt_seq_ops);
}
static const struct file_operations nvt_diff_fops = {
.owner = THIS_MODULE,
.open = nvt_diff_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
/*******************************************************
Description:
Novatek touchscreen extra function proc. file node
initial function.
return:
Executive outcomes. 0---succeed. -12---failed.
*******************************************************/
int32_t nvt_extra_proc_init(void)
{
NVT_proc_fw_version_entry = proc_create(NVT_FW_VERSION, 0444, NULL, &nvt_fw_version_fops);
if (NVT_proc_fw_version_entry == NULL) {
NVT_ERR("create proc/%s Failed!\n", NVT_FW_VERSION);
return -ENOMEM;
} else {
NVT_LOG("create proc/%s Succeeded!\n", NVT_FW_VERSION);
}
NVT_proc_baseline_entry = proc_create(NVT_BASELINE, 0444, NULL, &nvt_baseline_fops);
if (NVT_proc_baseline_entry == NULL) {
NVT_ERR("create proc/%s Failed!\n", NVT_BASELINE);
return -ENOMEM;
} else {
NVT_LOG("create proc/%s Succeeded!\n", NVT_BASELINE);
}
NVT_proc_raw_entry = proc_create(NVT_RAW, 0444, NULL, &nvt_raw_fops);
if (NVT_proc_raw_entry == NULL) {
NVT_ERR("create proc/%s Failed!\n", NVT_RAW);
return -ENOMEM;
} else {
NVT_LOG("create proc/%s Succeeded!\n", NVT_RAW);
}
NVT_proc_diff_entry = proc_create(NVT_DIFF, 0444, NULL, &nvt_diff_fops);
if (NVT_proc_diff_entry == NULL) {
NVT_ERR("create proc/%s Failed!\n", NVT_DIFF);
return -ENOMEM;
} else {
NVT_LOG("create proc/%s Succeeded!\n", NVT_DIFF);
}
return 0;
}
/*******************************************************
Description:
Novatek touchscreen extra function proc. file node
deinitial function.
return:
n.a.
*******************************************************/
void nvt_extra_proc_deinit(void)
{
if (NVT_proc_fw_version_entry != NULL) {
remove_proc_entry(NVT_FW_VERSION, NULL);
NVT_proc_fw_version_entry = NULL;
NVT_LOG("Removed /proc/%s\n", NVT_FW_VERSION);
}
if (NVT_proc_baseline_entry != NULL) {
remove_proc_entry(NVT_BASELINE, NULL);
NVT_proc_baseline_entry = NULL;
NVT_LOG("Removed /proc/%s\n", NVT_BASELINE);
}
if (NVT_proc_raw_entry != NULL) {
remove_proc_entry(NVT_RAW, NULL);
NVT_proc_raw_entry = NULL;
NVT_LOG("Removed /proc/%s\n", NVT_RAW);
}
if (NVT_proc_diff_entry != NULL) {
remove_proc_entry(NVT_DIFF, NULL);
NVT_proc_diff_entry = NULL;
NVT_LOG("Removed /proc/%s\n", NVT_DIFF);
}
}
#endif