diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/Android.mk b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/Android.mk deleted file mode 100644 index ef7d6b0fdbac..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/Android.mk +++ /dev/null @@ -1,14 +0,0 @@ -DLKM_DIR := motorola/kernel/modules -LOCAL_PATH := $(call my-dir) - -ifneq ($(FOCALTECH_TOUCH_IC_NAME),) - KERNEL_CFLAGS += CONFIG_INPUT_FOCALTECH_0FLASH_MMI_IC_NAME=$(FOCALTECH_TOUCH_IC_NAME) -else - KERNEL_CFLAGS += CONFIG_INPUT_FOCALTECH_0FLASH_MMI_IC_NAME=ft8719 -endif - -include $(CLEAR_VARS) -LOCAL_MODULE := focaltech_0flash_8756_mmi.ko -LOCAL_MODULE_TAGS := optional -LOCAL_MODULE_PATH := $(KERNEL_MODULES_OUT) -include $(DLKM_DIR)/AndroidKernelModule.mk diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/Kbuild b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/Kbuild deleted file mode 100644 index d423dc6e74c3..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/Kbuild +++ /dev/null @@ -1,29 +0,0 @@ -# add -Wall to try to catch everything we can. -EXTRA_CFLAGS += -Wall -EXTRA_CFLAGS += -I$(TOP)/motorola/kernel/modules/include \ - -I$(TOP)/motorola/kernel/modules/drivers/input/touchscreen/focaltech_0flash_8756_mmi \ - -I$(TOP)/motorola/kernel/modules/drivers/input/touchscreen/focaltech_0flash_8756_mmi/include \ - -I$(TOP)/motorola/kernel/modules/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test - -obj-m := focaltech_0flash_8756_mmi.o -focaltech_0flash_8756_mmi-objs += focaltech_core.o -focaltech_0flash_8756_mmi-objs += focaltech_esdcheck.o -focaltech_0flash_8756_mmi-objs += focaltech_ex_fun.o -focaltech_0flash_8756_mmi-objs += focaltech_ex_mode.o -focaltech_0flash_8756_mmi-objs += focaltech_flash.o -focaltech_0flash_8756_mmi-objs += focaltech_gesture.o -focaltech_0flash_8756_mmi-objs += focaltech_point_report_check.o -focaltech_0flash_8756_mmi-objs += focaltech_spi.o -focaltech_0flash_8756_mmi-objs += focaltech_test/focaltech_test.o -focaltech_0flash_8756_mmi-objs += focaltech_test/focaltech_test_ini.o - -ifneq ($(filter ft8719,$(CONFIG_INPUT_FOCALTECH_0FLASH_MMI_IC_NAME)),) - EXTRA_CFLAGS += -DCONFIG_INPUT_FOCALTECH_0FLASH_MMI_IC_NAME_FT8719 - focaltech_0flash_8756_mmi-objs += focaltech_test/supported_ic/focaltech_test_ft8719.o - focaltech_0flash_8756_mmi-objs += focaltech_flash_ft8719.o -endif -ifneq ($(filter ft8756,$(CONFIG_INPUT_FOCALTECH_0FLASH_MMI_IC_NAME)),) - EXTRA_CFLAGS += -DCONFIG_INPUT_FOCALTECH_0FLASH_MMI_IC_NAME_FT8756 - focaltech_0flash_8756_mmi-objs += focaltech_test/supported_ic/focaltech_test_ft8756.o - focaltech_0flash_8756_mmi-objs += focaltech_flash_ft8756.o -endif diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/Kconfig b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/Kconfig deleted file mode 100755 index 0c327bac9a96..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/Kconfig +++ /dev/null @@ -1,17 +0,0 @@ -# -# Focaltech Touchscreen driver configuration -# - -config TOUCHSCREEN_FTS - bool "Focaltech Touchscreen" - depends on I2C - default n - help - Say Y here if you have Focaltech touch panel. - If unsure, say N. - -config TOUCHSCREEN_FTS_DIRECTORY - string "Focaltech ts directory name" - default "focaltech_touch" - depends on TOUCHSCREEN_FTS - diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/Makefile b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/Makefile deleted file mode 100644 index 4191dea22679..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -KERNEL_SRC ?= /lib/modules/$(shell uname -r)/build - -all: - $(MAKE) -C $(KERNEL_SRC) M=$(shell pwd) modules $(KBUILD_OPTIONS) - -modules_install: - $(MAKE) INSTALL_MOD_STRIP=1 -C $(KERNEL_SRC) M=$(shell pwd) modules_install - -clean: - $(MAKE) -C $(KERNEL_SRC) M=$(PWD) clean diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/Makefile.kernel b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/Makefile.kernel deleted file mode 100755 index 8901b44be958..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/Makefile.kernel +++ /dev/null @@ -1,15 +0,0 @@ -# Makefile for the focaltech touchscreen drivers. - - -obj-$(CONFIG_TOUCHSCREEN_FTS) += focaltech_core.o -obj-$(CONFIG_TOUCHSCREEN_FTS) += focaltech_ex_fun.o -obj-$(CONFIG_TOUCHSCREEN_FTS) += focaltech_ex_mode.o -obj-$(CONFIG_TOUCHSCREEN_FTS) += focaltech_gesture.o -obj-$(CONFIG_TOUCHSCREEN_FTS) += focaltech_esdcheck.o -obj-$(CONFIG_TOUCHSCREEN_FTS) += focaltech_point_report_check.o -obj-$(CONFIG_TOUCHSCREEN_FTS) += focaltech_test/ - - -obj-$(CONFIG_TOUCHSCREEN_FTS) += focaltech_spi.o -obj-$(CONFIG_TOUCHSCREEN_FTS) += focaltech_flash.o - diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_common.h b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_common.h deleted file mode 100755 index 14a98f707f9c..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_common.h +++ /dev/null @@ -1,172 +0,0 @@ -/* - * - * FocalTech fts TouchScreen driver. - * - * Copyright (c) 2012-2019, Focaltech Ltd. All rights reserved. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -/***************************************************************************** -* -* File Name: focaltech_common.h -* -* Author: Focaltech Driver Team -* -* Created: 2016-08-16 -* -* Abstract: -* -* Reference: -* -*****************************************************************************/ - -#ifndef __LINUX_FOCALTECH_COMMON_H__ -#define __LINUX_FOCALTECH_COMMON_H__ - -#include "focaltech_config.h" - -/***************************************************************************** -* Macro definitions using #define -*****************************************************************************/ -#define FTS_DRIVER_VERSION "Focaltech V3.1 20190420" - -#define BYTE_OFF_0(x) (u8)((x) & 0xFF) -#define BYTE_OFF_8(x) (u8)((x >> 8) & 0xFF) -#define BYTE_OFF_16(x) (u8)((x >> 16) & 0xFF) -#define BYTE_OFF_24(x) (u8)((x >> 24) & 0xFF) -#define FLAGBIT(x) (0x00000001 << (x)) -#define FLAGBITS(x, y) ((0xFFFFFFFF >> (32 - (y) - 1)) & (0xFFFFFFFF << (x))) - -#define FLAG_ICSERIALS_LEN 8 -#define FLAG_HID_BIT 10 -#define FLAG_IDC_BIT 11 - -#define IC_SERIALS (FTS_CHIP_TYPE & FLAGBITS(0, FLAG_ICSERIALS_LEN-1)) -#define IC_TO_SERIALS(x) ((x) & FLAGBITS(0, FLAG_ICSERIALS_LEN-1)) -#define FTS_CHIP_IDC ((FTS_CHIP_TYPE & FLAGBIT(FLAG_IDC_BIT)) == FLAGBIT(FLAG_IDC_BIT)) -#define FTS_HID_SUPPORTTED ((FTS_CHIP_TYPE & FLAGBIT(FLAG_HID_BIT)) == FLAGBIT(FLAG_HID_BIT)) - -#if defined(CONFIG_INPUT_FOCALTECH_0FLASH_MMI_IC_NAME_FT8756) -#define FTS_CHIP_TYPE_MAPPING {{0x15, 0x87, 0x56, 0x87, 0x56, 0xF7, 0xA6, 0x00, 0x00}} -#elif defined(CONFIG_INPUT_FOCALTECH_0FLASH_MMI_IC_NAME_FT8719) -#define FTS_CHIP_TYPE_MAPPING {{0x0D,0x87, 0x19, 0x87, 0x19, 0x87, 0xA9, 0x87, 0xB9}} -#else -#define FTS_CHIP_TYPE_MAPPING {{0x0D,0x87, 0x19, 0x87, 0x19, 0x87, 0xA9, 0x87, 0xB9}} -#endif - -#define FILE_NAME_LENGTH 128 -#define ENABLE 1 -#define DISABLE 0 -#define VALID 1 -#define INVALID 0 -#define FTS_CMD_START1 0x55 -#define FTS_CMD_START2 0xAA -#define FTS_CMD_START_DELAY 10 -#define FTS_CMD_READ_ID 0x90 -#define FTS_CMD_READ_ID_LEN 4 -#define FTS_CMD_READ_ID_LEN_INCELL 1 -/*register address*/ -#define FTS_REG_INT_CNT 0x8F -#define FTS_REG_FLOW_WORK_CNT 0x91 -#define FTS_REG_WORKMODE 0x00 -#define FTS_REG_WORKMODE_FACTORY_VALUE 0x40 -#define FTS_REG_WORKMODE_WORK_VALUE 0x00 -#define FTS_REG_ESDCHECK_DISABLE 0x8D -#define FTS_REG_CHIP_ID 0xA3 -#define FTS_REG_CHIP_ID2 0x9F -#define FTS_REG_POWER_MODE 0xA5 -#define FTS_REG_POWER_MODE_SLEEP_VALUE 0x03 -#define FTS_REG_FW_VER 0xA6 -#define FTS_REG_VENDOR_ID 0xA8 -#define FTS_REG_LCD_BUSY_NUM 0xAB -#define FTS_REG_FACE_DEC_MODE_EN 0xB0 -#define FTS_REG_FACTORY_MODE_DETACH_FLAG 0xB4 -#define FTS_REG_FACE_DEC_MODE_STATUS 0x01 -#define FTS_REG_IDE_PARA_VER_ID 0xB5 -#define FTS_REG_IDE_PARA_STATUS 0xB6 -#define FTS_REG_GLOVE_MODE_EN 0xC0 -#define FTS_REG_COVER_MODE_EN 0xC1 -#define FTS_REG_CHARGER_MODE_EN 0x8B -#define FTS_REG_GESTURE_EN 0xD0 -#define FTS_REG_GESTURE_OUTPUT_ADDRESS 0xD3 -#define FTS_REG_MODULE_ID 0xE3 -#define FTS_REG_LIC_VER 0xE4 -#define FTS_REG_ESD_SATURATE 0xED - -#define FTS_SYSFS_ECHO_ON(buf) (buf[0] == '1') -#define FTS_SYSFS_ECHO_OFF(buf) (buf[0] == '0') - -#define kfree_safe(pbuf) do {\ - if (pbuf) {\ - kfree(pbuf);\ - pbuf = NULL;\ - }\ -} while(0) - -/***************************************************************************** -* Alternative mode (When something goes wrong, the modules may be able to solve the problem.) -*****************************************************************************/ -/* - * point report check - * default: disable - */ -#define FTS_POINT_REPORT_CHECK_EN 0 - -/***************************************************************************** -* Global variable or extern global variabls/functions -*****************************************************************************/ -struct ft_chip_t { - u64 type; - u8 chip_idh; - u8 chip_idl; - u8 rom_idh; - u8 rom_idl; - u8 pb_idh; - u8 pb_idl; - u8 bl_idh; - u8 bl_idl; -}; - -struct ts_ic_info { - bool is_incell; - bool hid_supported; - struct ft_chip_t ids; -}; - -/***************************************************************************** -* DEBUG function define here -*****************************************************************************/ -#if FTS_DEBUG_EN -#define FTS_DEBUG(fmt, args...) do { \ - printk("[FTS_TS]%s:"fmt"\n", __func__, ##args); \ -} while (0) - -#define FTS_FUNC_ENTER() do { \ - printk("[FTS_TS]%s: Enter\n", __func__); \ -} while (0) - -#define FTS_FUNC_EXIT() do { \ - printk("[FTS_TS]%s: Exit(%d)\n", __func__, __LINE__); \ -} while (0) -#else /* #if FTS_DEBUG_EN*/ -#define FTS_DEBUG(fmt, args...) -#define FTS_FUNC_ENTER() -#define FTS_FUNC_EXIT() -#endif - -#define FTS_INFO(fmt, args...) do { \ - printk(KERN_INFO "[FTS_TS/I]%s:"fmt"\n", __func__, ##args); \ -} while (0) - -#define FTS_ERROR(fmt, args...) do { \ - printk(KERN_ERR "[FTS_TS/E]%s:"fmt"\n", __func__, ##args); \ -} while (0) -#endif /* __LINUX_FOCALTECH_COMMON_H__ */ diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_config.h b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_config.h deleted file mode 100755 index d1d2356bb40e..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_config.h +++ /dev/null @@ -1,260 +0,0 @@ -/* - * - * FocalTech TouchScreen driver. - * - * Copyright (c) 2012-2019, FocalTech Systems, Ltd., all rights reserved. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -/************************************************************************ -* -* File Name: focaltech_config.h -* -* Author: Focaltech Driver Team -* -* Created: 2016-08-08 -* -* Abstract: global configurations -* -* Version: v1.0 -* -************************************************************************/ -#ifndef _LINUX_FOCLATECH_CONFIG_H_ -#define _LINUX_FOCLATECH_CONFIG_H_ - -/**************************************************/ -/****** G: A, I: B, S: C, U: D ******************/ -/****** chip type defines, do not modify *********/ -#define _FT8716 0x87160805 -#define _FT8736 0x87360806 -#define _FT8006M 0x80060807 -#define _FT7250 0x72500807 -#define _FT8607 0x86070809 -#define _FT8006U 0x8006D80B -#define _FT8006S 0x8006A80B -#define _FT8613 0x8613080C -#define _FT8719 0x8719080D -#define _FT8739 0x8739080E -#define _FT8615 0x8615080F -#define _FT8201 0x82010810 -#define _FT8006P 0x86220811 -#define _FT7251 0x72510812 -#define _FT7252 0x72520813 -#define _FT8613S 0x8613C814 -#define _FT8756 0x87560815 -#define _FT8302 0x83020816 -#define _FT8009 0x80090817 -#define _FT8656 0x86560818 - -#define _FT5416 0x54160402 -#define _FT5426 0x54260402 -#define _FT5435 0x54350402 -#define _FT5436 0x54360402 -#define _FT5526 0x55260402 -#define _FT5526I 0x5526B402 -#define _FT5446 0x54460402 -#define _FT5346 0x53460402 -#define _FT5446I 0x5446B402 -#define _FT5346I 0x5346B402 -#define _FT7661 0x76610402 -#define _FT7511 0x75110402 -#define _FT7421 0x74210402 -#define _FT7681 0x76810402 -#define _FT3C47U 0x3C47D402 -#define _FT3417 0x34170402 -#define _FT3517 0x35170402 -#define _FT3327 0x33270402 -#define _FT3427 0x34270402 -#define _FT7311 0x73110402 - -#define _FT5626 0x56260401 -#define _FT5726 0x57260401 -#define _FT5826B 0x5826B401 -#define _FT5826S 0x5826C401 -#define _FT7811 0x78110401 -#define _FT3D47 0x3D470401 -#define _FT3617 0x36170401 -#define _FT3717 0x37170401 -#define _FT3817B 0x3817B401 -#define _FT3517U 0x3517D401 - -#define _FT6236U 0x6236D003 -#define _FT6336G 0x6336A003 -#define _FT6336U 0x6336D003 -#define _FT6436U 0x6436D003 - -#define _FT3267 0x32670004 -#define _FT3367 0x33670004 - -#define _FT3327DQQ_XXX 0x3327D482 -#define _FT5446DQS_XXX 0x5446D482 - -#define _FT3518 0x35180481 -#define _FT3558 0x35580481 -#define _FT3528 0x35280481 -#define _FT5536 0x55360481 - -#define _FT5446U 0x5446D083 -#define _FT5456U 0x5456D083 -#define _FT3417U 0x3417D083 -#define _FT5426U 0x5426D083 -#define _FT3428 0x34280083 -#define _FT3437U 0x3437D083 - -#define _FT7302 0x73020084 -#define _FT7202 0x72020084 -#define _FT3308 0x33080084 - -#define _FT6346U 0x6346D085 -#define _FT6346G 0x6346A085 -#define _FT3067 0x30670085 -#define _FT3068 0x30680085 -#define _FT3168 0x31680085 -#define _FT3268 0x32680085 - -/*************************************************/ - -/* - * choose your ic chip type of focaltech - */ -#if defined(CONFIG_INPUT_FOCALTECH_0FLASH_MMI_IC_NAME_FT8756) -#define FTS_CHIP_TYPE _FT8756 -#define FTS_CHIP_NAME "ft8756" -#elif defined(CONFIG_INPUT_FOCALTECH_0FLASH_MMI_IC_NAME_FT8719) -#define FTS_CHIP_TYPE _FT8719 -#define FTS_CHIP_NAME "ft8719" -#else -#define FTS_CHIP_TYPE _FT8719 -#define FTS_CHIP_NAME "ft8719" -#endif - -/******************* Enables *********************/ -/*********** 1 to enable, 0 to disable ***********/ - -/* - * show debug log info - * enable it for debug, disable it for release - */ -#define FTS_DEBUG_EN 1 - -/* - * Linux MultiTouch Protocol - * 1: Protocol B(default), 0: Protocol A - */ -#define FTS_MT_PROTOCOL_B_EN 1 - -/* - * Report Pressure in multitouch - * 1:enable(default),0:disable -*/ -#define FTS_REPORT_PRESSURE_EN 1 - -/* - * Gesture function enable - * default: disable - */ -#define FTS_GESTURE_EN 0 - -/* - * ESD check & protection - * default: disable - */ -#define FTS_ESDCHECK_EN 0 - -/* - * Production test enable - * 1: enable, 0:disable(default) - */ -#define FTS_TEST_EN 1 - -/* - * Nodes for tools, please keep enable - */ -#define FTS_SYSFS_NODE_EN 1 -#define FTS_APK_NODE_EN 1 - -/* - * Pinctrl enable - * default: disable - */ -#define FTS_PINCTRL_EN 0 - -/* - * Customer power enable - * enable it when customer need control TP power - * default: disable - */ -#define FTS_POWER_SOURCE_CUST_EN 0 - -/****************************************************/ - -/********************** Upgrade ****************************/ -/* - * auto upgrade - */ -#define FTS_AUTO_UPGRADE_EN 0 - -/* - * auto upgrade for lcd cfg - */ -#define FTS_AUTO_LIC_UPGRADE_EN 0 - -/* - * Numbers of modules support - */ -#define FTS_GET_MODULE_NUM 0 - -/* - * module_id: mean vendor_id generally, also maybe gpio or lcm_id... - * If means vendor_id, the FTS_MODULE_ID = PANEL_ID << 8 + VENDOR_ID - * FTS_GET_MODULE_NUM == 0/1, no check module id, you may ignore them - * FTS_GET_MODULE_NUM >= 2, compatible with FTS_MODULE2_ID - * FTS_GET_MODULE_NUM >= 3, compatible with FTS_MODULE3_ID - */ -#define FTS_MODULE_ID 0x0000 -#define FTS_MODULE2_ID 0x0000 -#define FTS_MODULE3_ID 0x0000 - -/* - * Need set the following when get firmware via firmware_request() - * For example: if module'vendor is tianma, - * #define FTS_MODULE_NAME "tianma" - * then file_name will be "focaltech_ts_fw_tianma" - * You should rename fw to "focaltech_ts_fw_tianma", and push it into - * etc/firmware or by customers - */ -#define FTS_MODULE_NAME "" -#define FTS_MODULE2_NAME "" -#define FTS_MODULE3_NAME "" - -/* - * FW.i file for auto upgrade, you must replace it with your own - * define your own fw_file, the sample one to be replaced is invalid - * NOTE: if FTS_GET_MODULE_NUM > 1, it's the fw corresponding with FTS_VENDOR_ID - * NOTE: git may ignore xxx.i file - */ -#define FTS_UPGRADE_FW_FILE "include/firmware/fw_sample.i" - -/* - * if FTS_GET_MODULE_NUM >= 2, fw corrsponding with FTS_VENDOR_ID2 - * define your own fw_file, the sample one is invalid - */ -#define FTS_UPGRADE_FW2_FILE "include/firmware/fw_sample.h" - -/* - * if FTS_GET_MODULE_NUM >= 3, fw corrsponding with FTS_VENDOR_ID3 - * define your own fw_file, the sample one is invalid - */ -#define FTS_UPGRADE_FW3_FILE "include/firmware/fw_sample.h" - -/*********************************************************/ - -#endif /* _LINUX_FOCLATECH_CONFIG_H_ */ diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_core.c b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_core.c deleted file mode 100755 index 30aa7cafa2a7..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_core.c +++ /dev/null @@ -1,1789 +0,0 @@ -/* - * - * FocalTech TouchScreen driver. - * - * Copyright (c) 2012-2019, FocalTech Systems, Ltd., all rights reserved. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -/***************************************************************************** -* -* File Name: focaltech_core.c -* -* Author: Focaltech Driver Team -* -* Created: 2016-08-08 -* -* Abstract: entrance for focaltech ts driver -* -* Version: V1.0 -* -*****************************************************************************/ - -/***************************************************************************** -* Included header files -*****************************************************************************/ -#include -#include -#include -#include -#include -#include - -#ifdef CONFIG_DRM - #include -#elif defined(CONFIG_FB) - #include - #include -#elif defined(CONFIG_HAS_EARLYSUSPEND) - #include -#define FTS_SUSPEND_LEVEL 1 /* Early-suspend level */ -#endif -#include "focaltech_core.h" - -/***************************************************************************** -* Private constant and macro definitions using #define -*****************************************************************************/ -#define FTS_DRIVER_NAME "fts_ts" -#define INTERVAL_READ_REG 200 /* unit:ms */ -#define TIMEOUT_READ_REG 1000 /* unit:ms */ -#if FTS_POWER_SOURCE_CUST_EN -#define FTS_VTG_MIN_UV 2800000 -#define FTS_VTG_MAX_UV 3300000 -#define FTS_I2C_VTG_MIN_UV 1800000 -#define FTS_I2C_VTG_MAX_UV 1800000 -#endif - -/***************************************************************************** -* Global variable or extern global variabls/functions -*****************************************************************************/ -struct fts_ts_data *fts_data; - -/***************************************************************************** -* Static function prototypes -*****************************************************************************/ -static int fts_ts_suspend(struct device *dev); -static int fts_ts_resume(struct device *dev); - -/***************************************************************************** -* Name: fts_wait_tp_to_valid -* Brief: Read chip id until TP FW become valid(Timeout: TIMEOUT_READ_REG), -* need call when reset/power on/resume... -* Input: -* Output: -* Return: return 0 if tp valid, otherwise return error code -*****************************************************************************/ -int fts_wait_tp_to_valid(void) -{ - int ret = 0; - int cnt = 0; - u8 reg_value = 0; - u8 chip_id = fts_data->ic_info.ids.chip_idh; - - do { - ret = fts_read_reg(FTS_REG_CHIP_ID, ®_value); - if ((ret < 0) || (reg_value != chip_id)) { - FTS_DEBUG("TP Not Ready, ReadData = 0x%x", reg_value); - } else if (reg_value == chip_id) { - FTS_INFO("TP Ready, Device ID = 0x%x", reg_value); - return 0; - } - cnt++; - msleep(INTERVAL_READ_REG); - } while ((cnt * INTERVAL_READ_REG) < TIMEOUT_READ_REG); - - return -EIO; -} - -/***************************************************************************** -* Name: fts_tp_state_recovery -* Brief: Need execute this function when reset -* Input: -* Output: -* Return: -*****************************************************************************/ -void fts_tp_state_recovery(struct fts_ts_data *ts_data) -{ - FTS_FUNC_ENTER(); - /* wait tp stable */ - fts_wait_tp_to_valid(); - /* recover TP charger state 0x8B */ - /* recover TP glove state 0xC0 */ - /* recover TP cover state 0xC1 */ - fts_ex_mode_recovery(ts_data); - /* recover TP gesture state 0xD0 */ -#if FTS_GESTURE_EN - fts_gesture_recovery(ts_data); -#endif - FTS_FUNC_EXIT(); -} - -int fts_reset_proc(int hdelayms) -{ - FTS_DEBUG("tp reset"); - gpio_direction_output(fts_data->pdata->reset_gpio, 0); - msleep(5); - gpio_direction_output(fts_data->pdata->reset_gpio, 1); - if (hdelayms) { - msleep(hdelayms); - } - - return 0; -} - -void fts_irq_disable(void) -{ - unsigned long irqflags; - - FTS_FUNC_ENTER(); - spin_lock_irqsave(&fts_data->irq_lock, irqflags); - - if (!fts_data->irq_disabled) { - disable_irq_nosync(fts_data->irq); - fts_data->irq_disabled = true; - } - - spin_unlock_irqrestore(&fts_data->irq_lock, irqflags); - FTS_FUNC_EXIT(); -} - -void fts_irq_enable(void) -{ - unsigned long irqflags = 0; - - FTS_FUNC_ENTER(); - spin_lock_irqsave(&fts_data->irq_lock, irqflags); - - if (fts_data->irq_disabled) { - enable_irq(fts_data->irq); - fts_data->irq_disabled = false; - } - - spin_unlock_irqrestore(&fts_data->irq_lock, irqflags); - FTS_FUNC_EXIT(); -} - -void fts_hid2std(void) -{ - int ret = 0; - u8 buf[3] = {0xEB, 0xAA, 0x09}; - - ret = fts_write(buf, 3); - if (ret < 0) { - FTS_ERROR("hid2std cmd write fail"); - } else { - msleep(10); - buf[0] = buf[1] = buf[2] = 0; - ret = fts_read(NULL, 0, buf, 3); - if (ret < 0) { - FTS_ERROR("hid2std cmd read fail"); - } else if ((0xEB == buf[0]) && (0xAA == buf[1]) && (0x08 == buf[2])) { - FTS_DEBUG("hidi2c change to stdi2c successful"); - } else { - FTS_DEBUG("hidi2c change to stdi2c not support or fail"); - } - } -} - -static int fts_get_chip_types( - struct fts_ts_data *ts_data, - u8 id_h, u8 id_l, bool fw_valid) -{ - int i = 0; - struct ft_chip_t ctype[] = FTS_CHIP_TYPE_MAPPING; - u32 ctype_entries = sizeof(ctype) / sizeof(struct ft_chip_t); - - if ((0x0 == id_h) || (0x0 == id_l)) { - FTS_ERROR("id_h/id_l is 0"); - return -EINVAL; - } - - FTS_DEBUG("verify id:0x%02x%02x", id_h, id_l); - for (i = 0; i < ctype_entries; i++) { - if (VALID == fw_valid) { - if ((id_h == ctype[i].chip_idh) && (id_l == ctype[i].chip_idl)) - break; - } else { - if (((id_h == ctype[i].rom_idh) && (id_l == ctype[i].rom_idl)) - || ((id_h == ctype[i].pb_idh) && (id_l == ctype[i].pb_idl)) - || ((id_h == ctype[i].bl_idh) && (id_l == ctype[i].bl_idl))) - break; - } - } - - if (i >= ctype_entries) { - return -ENODATA; - } - - ts_data->ic_info.ids = ctype[i]; - return 0; -} - -static int fts_read_bootid(struct fts_ts_data *ts_data, u8 *id) -{ - int ret = 0; - u8 chip_id[2] = { 0 }; - u8 id_cmd[4] = { 0 }; - u32 id_cmd_len = 0; - - id_cmd[0] = FTS_CMD_START1; - id_cmd[1] = FTS_CMD_START2; - ret = fts_write(id_cmd, 2); - if (ret < 0) { - FTS_ERROR("start cmd write fail"); - return ret; - } - - msleep(FTS_CMD_START_DELAY); - id_cmd[0] = FTS_CMD_READ_ID; - id_cmd[1] = id_cmd[2] = id_cmd[3] = 0x00; - if (ts_data->ic_info.is_incell) - id_cmd_len = FTS_CMD_READ_ID_LEN_INCELL; - else - id_cmd_len = FTS_CMD_READ_ID_LEN; - ret = fts_read(id_cmd, id_cmd_len, chip_id, 2); - if ((ret < 0) || (0x0 == chip_id[0]) || (0x0 == chip_id[1])) { - FTS_ERROR("read boot id fail,read:0x%02x%02x", chip_id[0], chip_id[1]); - return -EIO; - } - - id[0] = chip_id[0]; - id[1] = chip_id[1]; - return 0; -} - -/***************************************************************************** -* Name: fts_get_ic_information -* Brief: read chip id to get ic information, after run the function, driver w- -* ill know which IC is it. -* If cant get the ic information, maybe not focaltech's touch IC, need -* unregister the driver -* Input: -* Output: -* Return: return 0 if get correct ic information, otherwise return error code -*****************************************************************************/ -static int fts_get_ic_information(struct fts_ts_data *ts_data) -{ - int ret = 0; - int cnt = 0; - u8 chip_id[2] = { 0 }; - - ts_data->ic_info.is_incell = FTS_CHIP_IDC; - ts_data->ic_info.hid_supported = FTS_HID_SUPPORTTED; - - for (cnt = 0; cnt < 3; cnt++) { - fts_reset_proc(0); - mdelay(8); - - ret = fts_read_bootid(ts_data, &chip_id[0]); - if (ret < 0) { - FTS_DEBUG("read boot id fail,retry:%d", cnt); - continue; - } - - ret = fts_get_chip_types(ts_data, chip_id[0], chip_id[1], INVALID); - if (ret < 0) { - FTS_DEBUG("can't get ic informaton,retry:%d", cnt); - continue; - } - - break; - } - - if (cnt >= 3) { - FTS_ERROR("get ic informaton fail"); - return -EIO; - } - - - FTS_INFO("get ic information, chip id = 0x%02x%02x", - ts_data->ic_info.ids.chip_idh, ts_data->ic_info.ids.chip_idl); - - return 0; -} - -/***************************************************************************** -* Reprot related -*****************************************************************************/ -static void fts_show_touch_buffer(u8 *data, int datalen) -{ - int i = 0; - int count = 0; - char *tmpbuf = NULL; - - tmpbuf = kzalloc(1024, GFP_KERNEL); - if (!tmpbuf) { - FTS_ERROR("tmpbuf zalloc fail"); - return; - } - - for (i = 0; i < datalen; i++) { - count += snprintf(tmpbuf + count, 1024 - count, "%02X,", data[i]); - if (count >= 1024) - break; - } - FTS_DEBUG("point buffer:%s", tmpbuf); - - if (tmpbuf) { - kfree(tmpbuf); - tmpbuf = NULL; - } -} - -void fts_release_all_finger(void) -{ - struct input_dev *input_dev = fts_data->input_dev; -#if FTS_MT_PROTOCOL_B_EN - u32 finger_count = 0; - u32 max_touches = fts_data->pdata->max_touch_number; -#endif - - FTS_FUNC_ENTER(); - mutex_lock(&fts_data->report_mutex); -#if FTS_MT_PROTOCOL_B_EN - for (finger_count = 0; finger_count < max_touches; finger_count++) { - input_mt_slot(input_dev, finger_count); - input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, false); - } -#else - input_mt_sync(input_dev); -#endif - input_report_key(input_dev, BTN_TOUCH, 0); - input_sync(input_dev); - - fts_data->touchs = 0; - fts_data->key_state = 0; - mutex_unlock(&fts_data->report_mutex); - FTS_FUNC_EXIT(); -} - -/***************************************************************************** -* Name: fts_input_report_key -* Brief: process key events,need report key-event if key enable. -* if point's coordinate is in (x_dim-50,y_dim-50) ~ (x_dim+50,y_dim+50), -* need report it to key event. -* x_dim: parse from dts, means key x_coordinate, dimension:+-50 -* y_dim: parse from dts, means key y_coordinate, dimension:+-50 -* Input: -* Output: -* Return: return 0 if it's key event, otherwise return error code -*****************************************************************************/ -static int fts_input_report_key(struct fts_ts_data *data, int index) -{ - int i = 0; - int x = data->events[index].x; - int y = data->events[index].y; - int *x_dim = &data->pdata->key_x_coords[0]; - int *y_dim = &data->pdata->key_y_coords[0]; - - if (!data->pdata->have_key) { - return -EINVAL; - } - for (i = 0; i < data->pdata->key_number; i++) { - if ((x >= x_dim[i] - FTS_KEY_DIM) && (x <= x_dim[i] + FTS_KEY_DIM) && - (y >= y_dim[i] - FTS_KEY_DIM) && (y <= y_dim[i] + FTS_KEY_DIM)) { - if (EVENT_DOWN(data->events[index].flag) - && !(data->key_state & (1 << i))) { - input_report_key(data->input_dev, data->pdata->keys[i], 1); - data->key_state |= (1 << i); - FTS_DEBUG("Key%d(%d,%d) DOWN!", i, x, y); - } else if (EVENT_UP(data->events[index].flag) - && (data->key_state & (1 << i))) { - input_report_key(data->input_dev, data->pdata->keys[i], 0); - data->key_state &= ~(1 << i); - FTS_DEBUG("Key%d(%d,%d) Up!", i, x, y); - } - return 0; - } - } - return -EINVAL; -} - -#if FTS_MT_PROTOCOL_B_EN -static int fts_input_report_b(struct fts_ts_data *data) -{ - int i = 0; - int uppoint = 0; - int touchs = 0; - bool va_reported = false; - u32 max_touch_num = data->pdata->max_touch_number; - struct ts_event *events = data->events; - - for (i = 0; i < data->touch_point; i++) { - if (fts_input_report_key(data, i) == 0) { - continue; - } - - va_reported = true; - input_mt_slot(data->input_dev, events[i].id); - - if (EVENT_DOWN(events[i].flag)) { - input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, true); - -#if FTS_REPORT_PRESSURE_EN - if (events[i].p <= 0) { - events[i].p = 0x3f; - } - input_report_abs(data->input_dev, ABS_MT_PRESSURE, events[i].p); -#endif - if (events[i].area <= 0) { - events[i].area = 0x09; - } - input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, events[i].area); - input_report_abs(data->input_dev, ABS_MT_POSITION_X, events[i].x); - input_report_abs(data->input_dev, ABS_MT_POSITION_Y, events[i].y); - - touchs |= BIT(events[i].id); - data->touchs |= BIT(events[i].id); - - if ((data->log_level >= 2) || - ((1 == data->log_level) && (FTS_TOUCH_DOWN == events[i].flag))) { - FTS_DEBUG("[B]P%d(%d, %d)[p:%d,tm:%d] DOWN!", - events[i].id, - events[i].x, events[i].y, - events[i].p, events[i].area); - } - } else { - uppoint++; - input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, false); - data->touchs &= ~BIT(events[i].id); - if (data->log_level >= 1) { - FTS_DEBUG("[B]P%d UP!", events[i].id); - } - } - } - - if (unlikely(data->touchs ^ touchs)) { - for (i = 0; i < max_touch_num; i++) { - if (BIT(i) & (data->touchs ^ touchs)) { - if (data->log_level >= 1) { - FTS_DEBUG("[B]P%d UP!", i); - } - va_reported = true; - input_mt_slot(data->input_dev, i); - input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, false); - } - } - } - data->touchs = touchs; - - if (va_reported) { - /* touchs==0, there's no point but key */ - if (EVENT_NO_DOWN(data) || (!touchs)) { - if (data->log_level >= 1) { - FTS_DEBUG("[B]Points All Up!"); - } - input_report_key(data->input_dev, BTN_TOUCH, 0); - } else { - input_report_key(data->input_dev, BTN_TOUCH, 1); - } - } - - input_sync(data->input_dev); - return 0; -} - -#else -static int fts_input_report_a(struct fts_ts_data *data) -{ - int i = 0; - int touchs = 0; - bool va_reported = false; - struct ts_event *events = data->events; - - for (i = 0; i < data->touch_point; i++) { - if (fts_input_report_key(data, i) == 0) { - continue; - } - - va_reported = true; - if (EVENT_DOWN(events[i].flag)) { - input_report_abs(data->input_dev, ABS_MT_TRACKING_ID, events[i].id); -#if FTS_REPORT_PRESSURE_EN - if (events[i].p <= 0) { - events[i].p = 0x3f; - } - input_report_abs(data->input_dev, ABS_MT_PRESSURE, events[i].p); -#endif - if (events[i].area <= 0) { - events[i].area = 0x09; - } - input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, events[i].area); - - input_report_abs(data->input_dev, ABS_MT_POSITION_X, events[i].x); - input_report_abs(data->input_dev, ABS_MT_POSITION_Y, events[i].y); - - input_mt_sync(data->input_dev); - - if ((data->log_level >= 2) || - ((1 == data->log_level) && (FTS_TOUCH_DOWN == events[i].flag))) { - FTS_DEBUG("[A]P%d(%d, %d)[p:%d,tm:%d] DOWN!", - events[i].id, - events[i].x, events[i].y, - events[i].p, events[i].area); - } - touchs++; - } - } - - /* last point down, current no point but key */ - if (data->touchs && !touchs) { - va_reported = true; - } - data->touchs = touchs; - - if (va_reported) { - if (EVENT_NO_DOWN(data)) { - if (data->log_level >= 1) { - FTS_DEBUG("[A]Points All Up!"); - } - input_report_key(data->input_dev, BTN_TOUCH, 0); - input_mt_sync(data->input_dev); - } else { - input_report_key(data->input_dev, BTN_TOUCH, 1); - } - } - - input_sync(data->input_dev); - return 0; -} -#endif - -static int fts_read_touchdata(struct fts_ts_data *data) -{ - int ret = 0; - u8 *buf = data->point_buf; - - memset(buf, 0xFF, data->pnt_buf_size); - - buf[0] = 0x01; - ret = fts_read(buf, 1, buf + 1, data->pnt_buf_size - 1); - if ((0xEF == buf[1]) && (0xEF == buf[2]) && (0xEF == buf[3])) { - /* check if need recovery fw */ - fts_fw_recovery(); - return 1; - } - - if ((ret < 0) || ((buf[1] & 0xF0) != 0x90)) { - FTS_ERROR("touch data(%x) abnormal,ret:%d", buf[1], ret); - return -EIO; - } - -#if FTS_GESTURE_EN - ret = fts_gesture_readdata(data, buf + FTS_TOUCH_DATA_LEN); - if (0 == ret) { - FTS_INFO("succuss to get gesture data in irq handler"); - return 1; - } -#endif - - - if (data->log_level >= 3) { - fts_show_touch_buffer(buf, data->pnt_buf_size); - } - - return 0; -} - -static int fts_read_parse_touchdata(struct fts_ts_data *data) -{ - int ret = 0; - int i = 0; - u8 pointid = 0; - int base = 0; - struct ts_event *events = data->events; - int max_touch_num = data->pdata->max_touch_number; - u8 *buf = data->point_buf; - - ret = fts_read_touchdata(data); - if (ret) { - return ret; - } - - data->point_num = buf[FTS_TOUCH_POINT_NUM] & 0x0F; - data->touch_point = 0; - - if (data->ic_info.is_incell) { - if ((data->point_num == 0x0F) && (buf[2] == 0xFF) && (buf[3] == 0xFF) - && (buf[4] == 0xFF) && (buf[5] == 0xFF) && (buf[6] == 0xFF)) { - FTS_DEBUG("touch buff is 0xff, need recovery state"); - fts_release_all_finger(); - fts_tp_state_recovery(data); - return -EIO; - } - } - - if (data->point_num > max_touch_num) { - FTS_INFO("invalid point_num(%d)", data->point_num); - return -EIO; - } - - for (i = 0; i < max_touch_num; i++) { - base = FTS_ONE_TCH_LEN * i; - pointid = (buf[FTS_TOUCH_ID_POS + base]) >> 4; - if (pointid >= FTS_MAX_ID) - break; - else if (pointid >= max_touch_num) { - FTS_ERROR("ID(%d) beyond max_touch_number", pointid); - return -EINVAL; - } - - data->touch_point++; - events[i].x = ((buf[FTS_TOUCH_X_H_POS + base] & 0x0F) << 8) + - (buf[FTS_TOUCH_X_L_POS + base] & 0xFF); - events[i].y = ((buf[FTS_TOUCH_Y_H_POS + base] & 0x0F) << 8) + - (buf[FTS_TOUCH_Y_L_POS + base] & 0xFF); - events[i].flag = buf[FTS_TOUCH_EVENT_POS + base] >> 6; - events[i].id = buf[FTS_TOUCH_ID_POS + base] >> 4; - events[i].area = buf[FTS_TOUCH_AREA_POS + base] >> 4; - events[i].p = buf[FTS_TOUCH_PRE_POS + base]; - - if (EVENT_DOWN(events[i].flag) && (data->point_num == 0)) { - FTS_INFO("abnormal touch data from fw"); - return -EIO; - } - } - - if (data->touch_point == 0) { - FTS_INFO("no touch point information"); - return -EIO; - } - - return 0; -} - -static void fts_irq_read_report(void) -{ - int ret = 0; - struct fts_ts_data *ts_data = fts_data; - -#if FTS_ESDCHECK_EN - fts_esdcheck_set_intr(1); -#endif - -#if FTS_POINT_REPORT_CHECK_EN - fts_prc_queue_work(ts_data); -#endif - - ret = fts_read_parse_touchdata(ts_data); - if (ret == 0) { - mutex_lock(&ts_data->report_mutex); -#if FTS_MT_PROTOCOL_B_EN - fts_input_report_b(ts_data); -#else - fts_input_report_a(ts_data); -#endif - mutex_unlock(&ts_data->report_mutex); - } - -#if FTS_ESDCHECK_EN - fts_esdcheck_set_intr(0); -#endif -} - -static irqreturn_t fts_irq_handler(int irq, void *data) -{ - fts_irq_read_report(); - return IRQ_HANDLED; -} - -static int fts_irq_registration(struct fts_ts_data *ts_data) -{ - int ret = 0; - struct fts_ts_platform_data *pdata = ts_data->pdata; - - ts_data->irq = gpio_to_irq(pdata->irq_gpio); - pdata->irq_gpio_flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT; - FTS_INFO("irq:%d, flag:%x", ts_data->irq, pdata->irq_gpio_flags); - ret = request_threaded_irq(ts_data->irq, NULL, fts_irq_handler, - pdata->irq_gpio_flags, - FTS_DRIVER_NAME, ts_data); - - return ret; -} - -static int fts_input_init(struct fts_ts_data *ts_data) -{ - int ret = 0; - int key_num = 0; - struct fts_ts_platform_data *pdata = ts_data->pdata; - struct input_dev *input_dev; - - FTS_FUNC_ENTER(); - input_dev = input_allocate_device(); - if (!input_dev) { - FTS_ERROR("Failed to allocate memory for input device"); - return -ENOMEM; - } - - /* Init and register Input device */ - input_dev->name = FTS_DRIVER_NAME; - input_dev->id.bustype = BUS_SPI; - - input_dev->dev.parent = ts_data->dev; - - input_set_drvdata(input_dev, ts_data); - - __set_bit(EV_SYN, input_dev->evbit); - __set_bit(EV_ABS, input_dev->evbit); - __set_bit(EV_KEY, input_dev->evbit); - __set_bit(BTN_TOUCH, input_dev->keybit); - __set_bit(INPUT_PROP_DIRECT, input_dev->propbit); - - if (pdata->have_key) { - FTS_INFO("set key capabilities"); - for (key_num = 0; key_num < pdata->key_number; key_num++) - input_set_capability(input_dev, EV_KEY, pdata->keys[key_num]); - } - -#if FTS_MT_PROTOCOL_B_EN - input_mt_init_slots(input_dev, pdata->max_touch_number, INPUT_MT_DIRECT); -#else - input_set_abs_params(input_dev, ABS_MT_TRACKING_ID, 0, 0x0F, 0, 0); -#endif - input_set_abs_params(input_dev, ABS_MT_POSITION_X, pdata->x_min, pdata->x_max, 0, 0); - input_set_abs_params(input_dev, ABS_MT_POSITION_Y, pdata->y_min, pdata->y_max, 0, 0); - input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 0xFF, 0, 0); -#if FTS_REPORT_PRESSURE_EN - input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 0xFF, 0, 0); -#endif - - ret = input_register_device(input_dev); - if (ret) { - FTS_ERROR("Input device registration failed"); - input_set_drvdata(input_dev, NULL); - input_free_device(input_dev); - input_dev = NULL; - return ret; - } - - ts_data->input_dev = input_dev; - - FTS_FUNC_EXIT(); - return 0; -} - -static int fts_report_buffer_init(struct fts_ts_data *ts_data) -{ - int point_num = 0; - int events_num = 0; - - point_num = FTS_MAX_POINTS_SUPPORT; - ts_data->pnt_buf_size = FTS_TOUCH_DATA_LEN + FTS_GESTURE_DATA_LEN; - - ts_data->point_buf = (u8 *)kzalloc(ts_data->pnt_buf_size + 1, GFP_KERNEL); - if (!ts_data->point_buf) { - FTS_ERROR("failed to alloc memory for point buf"); - return -ENOMEM; - } - - events_num = point_num * sizeof(struct ts_event); - ts_data->events = (struct ts_event *)kzalloc(events_num, GFP_KERNEL); - if (!ts_data->events) { - FTS_ERROR("failed to alloc memory for point events"); - kfree_safe(ts_data->point_buf); - return -ENOMEM; - } - - return 0; -} - -#if FTS_POWER_SOURCE_CUST_EN -/***************************************************************************** -* Power Control -*****************************************************************************/ -#if FTS_PINCTRL_EN -static int fts_pinctrl_init(struct fts_ts_data *ts) -{ - int ret = 0; - - ts->pinctrl = devm_pinctrl_get(ts->dev); - if (IS_ERR_OR_NULL(ts->pinctrl)) { - FTS_ERROR("Failed to get pinctrl, please check dts"); - ret = PTR_ERR(ts->pinctrl); - goto err_pinctrl_get; - } - - ts->pins_active = pinctrl_lookup_state(ts->pinctrl, "pmx_ts_active"); - if (IS_ERR_OR_NULL(ts->pins_active)) { - FTS_ERROR("Pin state[active] not found"); - ret = PTR_ERR(ts->pins_active); - goto err_pinctrl_lookup; - } - - ts->pins_suspend = pinctrl_lookup_state(ts->pinctrl, "pmx_ts_suspend"); - if (IS_ERR_OR_NULL(ts->pins_suspend)) { - FTS_ERROR("Pin state[suspend] not found"); - ret = PTR_ERR(ts->pins_suspend); - goto err_pinctrl_lookup; - } - - ts->pins_release = pinctrl_lookup_state(ts->pinctrl, "pmx_ts_release"); - if (IS_ERR_OR_NULL(ts->pins_release)) { - FTS_ERROR("Pin state[release] not found"); - ret = PTR_ERR(ts->pins_release); - } - - return 0; -err_pinctrl_lookup: - if (ts->pinctrl) { - devm_pinctrl_put(ts->pinctrl); - } -err_pinctrl_get: - ts->pinctrl = NULL; - ts->pins_release = NULL; - ts->pins_suspend = NULL; - ts->pins_active = NULL; - return ret; -} - -static int fts_pinctrl_select_normal(struct fts_ts_data *ts) -{ - int ret = 0; - - if (ts->pinctrl && ts->pins_active) { - ret = pinctrl_select_state(ts->pinctrl, ts->pins_active); - if (ret < 0) { - FTS_ERROR("Set normal pin state error:%d", ret); - } - } - - return ret; -} - -static int fts_pinctrl_select_suspend(struct fts_ts_data *ts) -{ - int ret = 0; - - if (ts->pinctrl && ts->pins_suspend) { - ret = pinctrl_select_state(ts->pinctrl, ts->pins_suspend); - if (ret < 0) { - FTS_ERROR("Set suspend pin state error:%d", ret); - } - } - - return ret; -} - -static int fts_pinctrl_select_release(struct fts_ts_data *ts) -{ - int ret = 0; - - if (ts->pinctrl) { - if (IS_ERR_OR_NULL(ts->pins_release)) { - devm_pinctrl_put(ts->pinctrl); - ts->pinctrl = NULL; - } else { - ret = pinctrl_select_state(ts->pinctrl, ts->pins_release); - if (ret < 0) - FTS_ERROR("Set gesture pin state error:%d", ret); - } - } - - return ret; -} -#endif /* FTS_PINCTRL_EN */ - -static int fts_power_source_ctrl(struct fts_ts_data *ts_data, int enable) -{ - int ret = 0; - - if (IS_ERR_OR_NULL(ts_data->vdd)) { - FTS_ERROR("vdd is invalid"); - return -EINVAL; - } - - FTS_FUNC_ENTER(); - if (enable) { - if (ts_data->power_disabled) { - FTS_DEBUG("regulator enable !"); - gpio_direction_output(ts_data->pdata->reset_gpio, 0); - msleep(1); - ret = regulator_enable(ts_data->vdd); - if (ret) { - FTS_ERROR("enable vdd regulator failed,ret=%d", ret); - } - - if (!IS_ERR_OR_NULL(ts_data->vcc_i2c)) { - ret = regulator_enable(ts_data->vcc_i2c); - if (ret) { - FTS_ERROR("enable vcc_i2c regulator failed,ret=%d", ret); - } - } - ts_data->power_disabled = false; - } - } else { - if (!ts_data->power_disabled) { - FTS_DEBUG("regulator disable !"); - gpio_direction_output(ts_data->pdata->reset_gpio, 0); - msleep(1); - ret = regulator_disable(ts_data->vdd); - if (ret) { - FTS_ERROR("disable vdd regulator failed,ret=%d", ret); - } - if (!IS_ERR_OR_NULL(ts_data->vcc_i2c)) { - ret = regulator_disable(ts_data->vcc_i2c); - if (ret) { - FTS_ERROR("disable vcc_i2c regulator failed,ret=%d", ret); - } - } - ts_data->power_disabled = true; - } - } - - FTS_FUNC_EXIT(); - return ret; -} - -/***************************************************************************** -* Name: fts_power_source_init -* Brief: Init regulator power:vdd/vcc_io(if have), generally, no vcc_io -* vdd---->vdd-supply in dts, kernel will auto add "-supply" to parse -* Must be call after fts_gpio_configure() execute,because this function -* will operate reset-gpio which request gpio in fts_gpio_configure() -* Input: -* Output: -* Return: return 0 if init power successfully, otherwise return error code -*****************************************************************************/ -static int fts_power_source_init(struct fts_ts_data *ts_data) -{ - int ret = 0; - - FTS_FUNC_ENTER(); - ts_data->vdd = regulator_get(ts_data->dev, "vdd"); - if (IS_ERR_OR_NULL(ts_data->vdd)) { - ret = PTR_ERR(ts_data->vdd); - FTS_ERROR("get vdd regulator failed,ret=%d", ret); - return ret; - } - - if (regulator_count_voltages(ts_data->vdd) > 0) { - ret = regulator_set_voltage(ts_data->vdd, FTS_VTG_MIN_UV, - FTS_VTG_MAX_UV); - if (ret) { - FTS_ERROR("vdd regulator set_vtg failed ret=%d", ret); - regulator_put(ts_data->vdd); - return ret; - } - } - - ts_data->vcc_i2c = regulator_get(ts_data->dev, "vcc_i2c"); - if (!IS_ERR_OR_NULL(ts_data->vcc_i2c)) { - if (regulator_count_voltages(ts_data->vcc_i2c) > 0) { - ret = regulator_set_voltage(ts_data->vcc_i2c, - FTS_I2C_VTG_MIN_UV, - FTS_I2C_VTG_MAX_UV); - if (ret) { - FTS_ERROR("vcc_i2c regulator set_vtg failed,ret=%d", ret); - regulator_put(ts_data->vcc_i2c); - } - } - } - -#if FTS_PINCTRL_EN - fts_pinctrl_init(ts_data); - fts_pinctrl_select_normal(ts_data); -#endif - - ts_data->power_disabled = true; - ret = fts_power_source_ctrl(ts_data, ENABLE); - if (ret) { - FTS_ERROR("fail to enable power(regulator)"); - } - - FTS_FUNC_EXIT(); - return ret; -} - -static int fts_power_source_exit(struct fts_ts_data *ts_data) -{ -#if FTS_PINCTRL_EN - fts_pinctrl_select_release(ts_data); -#endif - - fts_power_source_ctrl(ts_data, DISABLE); - - if (!IS_ERR_OR_NULL(ts_data->vdd)) { - if (regulator_count_voltages(ts_data->vdd) > 0) - regulator_set_voltage(ts_data->vdd, 0, FTS_VTG_MAX_UV); - regulator_put(ts_data->vdd); - } - - if (!IS_ERR_OR_NULL(ts_data->vcc_i2c)) { - if (regulator_count_voltages(ts_data->vcc_i2c) > 0) - regulator_set_voltage(ts_data->vcc_i2c, 0, FTS_I2C_VTG_MAX_UV); - regulator_put(ts_data->vcc_i2c); - } - - return 0; -} - -static int fts_power_source_suspend(struct fts_ts_data *ts_data) -{ - int ret = 0; - -#if FTS_PINCTRL_EN - fts_pinctrl_select_suspend(ts_data); -#endif - - ret = fts_power_source_ctrl(ts_data, DISABLE); - if (ret < 0) { - FTS_ERROR("power off fail, ret=%d", ret); - } - - return ret; -} - -static int fts_power_source_resume(struct fts_ts_data *ts_data) -{ - int ret = 0; - -#if FTS_PINCTRL_EN - fts_pinctrl_select_normal(ts_data); -#endif - - ret = fts_power_source_ctrl(ts_data, ENABLE); - if (ret < 0) { - FTS_ERROR("power on fail, ret=%d", ret); - } - - return ret; -} -#endif /* FTS_POWER_SOURCE_CUST_EN */ - -static int fts_gpio_configure(struct fts_ts_data *data) -{ - int ret = 0; - - FTS_FUNC_ENTER(); - /* request irq gpio */ - if (gpio_is_valid(data->pdata->irq_gpio)) { - ret = gpio_request(data->pdata->irq_gpio, "fts_irq_gpio"); - if (ret) { - FTS_ERROR("[GPIO]irq gpio request failed"); - goto err_irq_gpio_req; - } - - ret = gpio_direction_input(data->pdata->irq_gpio); - if (ret) { - FTS_ERROR("[GPIO]set_direction for irq gpio failed"); - goto err_irq_gpio_dir; - } - } - - /* request reset gpio */ - if (gpio_is_valid(data->pdata->reset_gpio)) { - ret = gpio_request(data->pdata->reset_gpio, "fts_reset_gpio"); - if (ret) { - FTS_ERROR("[GPIO]reset gpio request failed"); - goto err_irq_gpio_dir; - } - - ret = gpio_direction_output(data->pdata->reset_gpio, 1); - if (ret) { - FTS_ERROR("[GPIO]set_direction for reset gpio failed"); - goto err_reset_gpio_dir; - } - } - - FTS_FUNC_EXIT(); - return 0; - -err_reset_gpio_dir: - if (gpio_is_valid(data->pdata->reset_gpio)) - gpio_free(data->pdata->reset_gpio); -err_irq_gpio_dir: - if (gpio_is_valid(data->pdata->irq_gpio)) - gpio_free(data->pdata->irq_gpio); -err_irq_gpio_req: - FTS_FUNC_EXIT(); - return ret; -} - -static int fts_get_dt_coords(struct device *dev, char *name, - struct fts_ts_platform_data *pdata) -{ - int ret = 0; - u32 coords[FTS_COORDS_ARR_SIZE] = { 0 }; - struct property *prop; - struct device_node *np = dev->of_node; - int coords_size; - - prop = of_find_property(np, name, NULL); - if (!prop) - return -EINVAL; - if (!prop->value) - return -ENODATA; - - coords_size = prop->length / sizeof(u32); - if (coords_size != FTS_COORDS_ARR_SIZE) { - FTS_ERROR("invalid:%s, size:%d", name, coords_size); - return -EINVAL; - } - - ret = of_property_read_u32_array(np, name, coords, coords_size); - if (ret < 0) { - FTS_ERROR("Unable to read %s, please check dts", name); - pdata->x_min = FTS_X_MIN_DISPLAY_DEFAULT; - pdata->y_min = FTS_Y_MIN_DISPLAY_DEFAULT; - pdata->x_max = FTS_X_MAX_DISPLAY_DEFAULT; - pdata->y_max = FTS_Y_MAX_DISPLAY_DEFAULT; - return -ENODATA; - } else { - pdata->x_min = coords[0]; - pdata->y_min = coords[1]; - pdata->x_max = coords[2]; - pdata->y_max = coords[3]; - } - - FTS_INFO("display x(%d %d) y(%d %d)", pdata->x_min, pdata->x_max, - pdata->y_min, pdata->y_max); - return 0; -} - -static int fts_parse_dt(struct device *dev, struct fts_ts_platform_data *pdata) -{ - int ret = 0; - struct device_node *np = dev->of_node; - u32 temp_val = 0; - - FTS_FUNC_ENTER(); - - ret = fts_get_dt_coords(dev, "focaltech,display-coords", pdata); - if (ret < 0) - FTS_ERROR("Unable to get display-coords"); - - /* key */ - pdata->have_key = of_property_read_bool(np, "focaltech,have-key"); - if (pdata->have_key) { - ret = of_property_read_u32(np, "focaltech,key-number", &pdata->key_number); - if (ret < 0) - FTS_ERROR("Key number undefined!"); - - ret = of_property_read_u32_array(np, "focaltech,keys", - pdata->keys, pdata->key_number); - if (ret < 0) - FTS_ERROR("Keys undefined!"); - else if (pdata->key_number > FTS_MAX_KEYS) - pdata->key_number = FTS_MAX_KEYS; - - ret = of_property_read_u32_array(np, "focaltech,key-x-coords", - pdata->key_x_coords, - pdata->key_number); - if (ret < 0) - FTS_ERROR("Key Y Coords undefined!"); - - ret = of_property_read_u32_array(np, "focaltech,key-y-coords", - pdata->key_y_coords, - pdata->key_number); - if (ret < 0) - FTS_ERROR("Key X Coords undefined!"); - - FTS_INFO("VK Number:%d, key:(%d,%d,%d), " - "coords:(%d,%d),(%d,%d),(%d,%d)", - pdata->key_number, - pdata->keys[0], pdata->keys[1], pdata->keys[2], - pdata->key_x_coords[0], pdata->key_y_coords[0], - pdata->key_x_coords[1], pdata->key_y_coords[1], - pdata->key_x_coords[2], pdata->key_y_coords[2]); - } - - /* reset, irq gpio info */ - pdata->reset_gpio = of_get_named_gpio_flags(np, "focaltech,reset-gpio", - 0, &pdata->reset_gpio_flags); - if (pdata->reset_gpio < 0) - FTS_ERROR("Unable to get reset_gpio"); - - pdata->irq_gpio = of_get_named_gpio_flags(np, "focaltech,irq-gpio", - 0, &pdata->irq_gpio_flags); - if (pdata->irq_gpio < 0) - FTS_ERROR("Unable to get irq_gpio"); - - ret = of_property_read_u32(np, "focaltech,max-touch-number", &temp_val); - if (ret < 0) { - FTS_ERROR("Unable to get max-touch-number, please check dts"); - pdata->max_touch_number = FTS_MAX_POINTS_SUPPORT; - } else { - if (temp_val < 2) - pdata->max_touch_number = 2; /* max_touch_number must >= 2 */ - else if (temp_val > FTS_MAX_POINTS_SUPPORT) - pdata->max_touch_number = FTS_MAX_POINTS_SUPPORT; - else - pdata->max_touch_number = temp_val; - } - - FTS_INFO("max touch number:%d, irq gpio:%d, reset gpio:%d", - pdata->max_touch_number, pdata->irq_gpio, pdata->reset_gpio); - - FTS_FUNC_EXIT(); - return 0; -} - -#if defined(CONFIG_FB) || defined(CONFIG_DRM) -static void fts_resume_work(struct work_struct *work) -{ - struct fts_ts_data *ts_data = container_of(work, struct fts_ts_data, - resume_work); - - fts_ts_resume(ts_data->dev); -} -#endif - -#ifdef CONFIG_DRM -int drm_notifier_callback(struct notifier_block *self, - unsigned long event, void *data) -{ - struct msm_drm_notifier *evdata = data; - int *blank; - struct fts_ts_data *ts_data = - container_of(self, struct fts_ts_data, fb_notif); - - if (!evdata || (evdata->id != 0)) { - return 0; - } - - if (!(event == MSM_DRM_EARLY_EVENT_BLANK || event == MSM_DRM_EVENT_BLANK)) { - FTS_INFO("event(%lu) do not need process\n", event); - return 0; - } - blank = evdata->data; - FTS_INFO("DRM event:%lu,blank:%d", event, *blank); - switch (*blank) { - case MSM_DRM_BLANK_UNBLANK: - if (MSM_DRM_EARLY_EVENT_BLANK == event) { - FTS_INFO("resume: event = %lu, not care\n", event); - } else if (MSM_DRM_EVENT_BLANK == event) { - queue_work(fts_data->ts_workqueue, &fts_data->resume_work); - } - break; - case MSM_DRM_BLANK_POWERDOWN: - if (MSM_DRM_EARLY_EVENT_BLANK == event) { - cancel_work_sync(&fts_data->resume_work); - fts_ts_suspend(ts_data->dev); - } else if (MSM_DRM_EVENT_BLANK == event) { - FTS_INFO("suspend: event = %lu, not care\n", event); - } - break; - default: - FTS_INFO("DAM BLANK(%d) do not need process\n", *blank); - break; - } - - return 0; -} -#elif defined(CONFIG_FB) -static int fb_notifier_callback(struct notifier_block *self, - unsigned long event, void *data) -{ - struct fb_event *evdata = data; - int *blank = NULL; - struct fts_ts_data *ts_data = container_of(self, struct fts_ts_data, - fb_notif); - - if (!(event == FB_EARLY_EVENT_BLANK || event == FB_EVENT_BLANK)) { - FTS_INFO("event(%lu) do not need process\n", event); - return 0; - } - - blank = evdata->data; - FTS_INFO("FB event:%lu,blank:%d", event, *blank); - switch (*blank) { - case FB_BLANK_UNBLANK: - if (FB_EARLY_EVENT_BLANK == event) { - FTS_INFO("resume: event = %lu, not care\n", event); - } else if (FB_EVENT_BLANK == event) { - queue_work(fts_data->ts_workqueue, &fts_data->resume_work); - } - break; - case FB_BLANK_POWERDOWN: - if (FB_EARLY_EVENT_BLANK == event) { - cancel_work_sync(&fts_data->resume_work); - fts_ts_suspend(ts_data->dev); - } else if (FB_EVENT_BLANK == event) { - FTS_INFO("suspend: event = %lu, not care\n", event); - } - break; - default: - FTS_INFO("FB BLANK(%d) do not need process\n", *blank); - break; - } - - return 0; -} -#elif defined(CONFIG_HAS_EARLYSUSPEND) -static void fts_ts_early_suspend(struct early_suspend *handler) -{ - struct fts_ts_data *ts_data = container_of(handler, struct fts_ts_data, - early_suspend); - - fts_ts_suspend(ts_data->dev); -} - -static void fts_ts_late_resume(struct early_suspend *handler) -{ - struct fts_ts_data *ts_data = container_of(handler, struct fts_ts_data, - early_suspend); - - fts_ts_resume(ts_data->dev); -} -#endif - -static int fts_ts_probe_entry(struct fts_ts_data *ts_data) -{ - int ret = 0; - int pdata_size = sizeof(struct fts_ts_platform_data); - - FTS_FUNC_ENTER(); - FTS_INFO("%s", FTS_DRIVER_VERSION); - ts_data->pdata = kzalloc(pdata_size, GFP_KERNEL); - if (!ts_data->pdata) { - FTS_ERROR("allocate memory for platform_data fail"); - return -ENOMEM; - } - - if (ts_data->dev->of_node) { - ret = fts_parse_dt(ts_data->dev, ts_data->pdata); - if (ret) - FTS_ERROR("device-tree parse fail"); - } else { - if (ts_data->dev->platform_data) { - memcpy(ts_data->pdata, ts_data->dev->platform_data, pdata_size); - } else { - FTS_ERROR("platform_data is null"); - return -ENODEV; - } - } - - ts_data->ts_workqueue = create_singlethread_workqueue("fts_wq"); - if (!ts_data->ts_workqueue) { - FTS_ERROR("create fts workqueue fail"); - } - - spin_lock_init(&ts_data->irq_lock); - mutex_init(&ts_data->report_mutex); - mutex_init(&ts_data->bus_lock); - - /* Init communication interface */ - ret = fts_bus_init(ts_data); - if (ret) { - FTS_ERROR("bus initialize fail"); - goto err_bus_init; - } - - ret = fts_input_init(ts_data); - if (ret) { - FTS_ERROR("input initialize fail"); - goto err_input_init; - } - - ret = fts_report_buffer_init(ts_data); - if (ret) { - FTS_ERROR("report buffer init fail"); - goto err_report_buffer; - } - - ret = fts_gpio_configure(ts_data); - if (ret) { - FTS_ERROR("configure the gpios fail"); - goto err_gpio_config; - } - -#if FTS_POWER_SOURCE_CUST_EN - ret = fts_power_source_init(ts_data); - if (ret) { - FTS_ERROR("fail to get power(regulator)"); - goto err_power_init; - } -#endif - -#if (!FTS_CHIP_IDC) - fts_reset_proc(200); -#endif - - ret = fts_get_ic_information(ts_data); - if (ret) { - FTS_ERROR("not focal IC, unregister driver"); - goto err_irq_req; - } - -#if FTS_APK_NODE_EN - ret = fts_create_apk_debug_channel(ts_data); - if (ret) { - FTS_ERROR("create apk debug node fail"); - } -#endif - -#if FTS_SYSFS_NODE_EN - ret = fts_create_sysfs(ts_data); - if (ret) { - FTS_ERROR("create sysfs node fail"); - } -#endif - -#if FTS_POINT_REPORT_CHECK_EN - ret = fts_point_report_check_init(ts_data); - if (ret) { - FTS_ERROR("init point report check fail"); - } -#endif - - ret = fts_ex_mode_init(ts_data); - if (ret) { - FTS_ERROR("init glove/cover/charger fail"); - } - -#if FTS_GESTURE_EN - ret = fts_gesture_init(ts_data); - if (ret) { - FTS_ERROR("init gesture fail"); - } -#endif - -#if FTS_TEST_EN - ret = fts_test_init(ts_data); - if (ret) { - FTS_ERROR("init production test fail"); - } -#endif - -#if FTS_ESDCHECK_EN - ret = fts_esdcheck_init(ts_data); - if (ret) { - FTS_ERROR("init esd check fail"); - } -#endif - - ret = fts_irq_registration(ts_data); - if (ret) { - FTS_ERROR("request irq failed"); - goto err_irq_req; - } - - ret = fts_fwupg_init(ts_data); - if (ret) { - FTS_ERROR("init fw upgrade fail"); - } - -#ifdef CONFIG_DRM - if (ts_data->ts_workqueue) { - INIT_WORK(&ts_data->resume_work, fts_resume_work); - } - ts_data->fb_notif.notifier_call = drm_notifier_callback; - ret = msm_drm_register_client(&ts_data->fb_notif); - if (ret) { - FTS_ERROR("[DRM]Unable to register fb_notifier: %d\n", ret); - } -#elif defined(CONFIG_FB) - if (ts_data->ts_workqueue) { - INIT_WORK(&ts_data->resume_work, fts_resume_work); - } - ts_data->fb_notif.notifier_call = fb_notifier_callback; - ret = fb_register_client(&ts_data->fb_notif); - if (ret) { - FTS_ERROR("[FB]Unable to register fb_notifier: %d", ret); - } -#elif defined(CONFIG_HAS_EARLYSUSPEND) - ts_data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + FTS_SUSPEND_LEVEL; - ts_data->early_suspend.suspend = fts_ts_early_suspend; - ts_data->early_suspend.resume = fts_ts_late_resume; - register_early_suspend(&ts_data->early_suspend); -#endif - - FTS_FUNC_EXIT(); - return 0; - -err_irq_req: -#if FTS_POWER_SOURCE_CUST_EN -err_power_init: - fts_power_source_exit(ts_data); -#endif - if (gpio_is_valid(ts_data->pdata->reset_gpio)) - gpio_free(ts_data->pdata->reset_gpio); - if (gpio_is_valid(ts_data->pdata->irq_gpio)) - gpio_free(ts_data->pdata->irq_gpio); -err_gpio_config: - kfree_safe(ts_data->point_buf); - kfree_safe(ts_data->events); -err_report_buffer: - input_unregister_device(ts_data->input_dev); -err_input_init: - if (ts_data->ts_workqueue) - destroy_workqueue(ts_data->ts_workqueue); -err_bus_init: - kfree_safe(ts_data->bus_tx_buf); - kfree_safe(ts_data->bus_rx_buf); - kfree_safe(ts_data->pdata); - - FTS_FUNC_EXIT(); - return ret; -} - -static int fts_ts_remove_entry(struct fts_ts_data *ts_data) -{ - FTS_FUNC_ENTER(); - -#if FTS_POINT_REPORT_CHECK_EN - fts_point_report_check_exit(ts_data); -#endif - -#if FTS_APK_NODE_EN - fts_release_apk_debug_channel(ts_data); -#endif - -#if FTS_SYSFS_NODE_EN - fts_remove_sysfs(ts_data); -#endif - - fts_ex_mode_exit(ts_data); - - fts_fwupg_exit(ts_data); - -#if FTS_TEST_EN - fts_test_exit(ts_data); -#endif - -#if FTS_ESDCHECK_EN - fts_esdcheck_exit(ts_data); -#endif - -#if FTS_GESTURE_EN - fts_gesture_exit(ts_data); -#endif - - fts_bus_exit(ts_data); - - free_irq(ts_data->irq, ts_data); - input_unregister_device(ts_data->input_dev); - - if (ts_data->ts_workqueue) - destroy_workqueue(ts_data->ts_workqueue); - -#ifdef CONFIG_DRM - if (msm_drm_unregister_client(&ts_data->fb_notif)) - FTS_ERROR("Error occurred while unregistering fb_notifier.\n"); -#elif defined(CONFIG_FB) - if (fb_unregister_client(&ts_data->fb_notif)) - FTS_ERROR("Error occurred while unregistering fb_notifier.\n"); -#elif defined(CONFIG_HAS_EARLYSUSPEND) - unregister_early_suspend(&ts_data->early_suspend); -#endif - - if (gpio_is_valid(ts_data->pdata->reset_gpio)) - gpio_free(ts_data->pdata->reset_gpio); - - if (gpio_is_valid(ts_data->pdata->irq_gpio)) - gpio_free(ts_data->pdata->irq_gpio); - -#if FTS_POWER_SOURCE_CUST_EN - fts_power_source_exit(ts_data); -#endif - - kfree_safe(ts_data->point_buf); - kfree_safe(ts_data->events); - - kfree_safe(ts_data->pdata); - kfree_safe(ts_data); - - FTS_FUNC_EXIT(); - - return 0; -} - -static int fts_ts_suspend(struct device *dev) -{ - int ret = 0; - struct fts_ts_data *ts_data = fts_data; - - FTS_FUNC_ENTER(); - if (ts_data->suspended) { - FTS_INFO("Already in suspend state"); - return 0; - } - - if (ts_data->fw_loading) { - FTS_INFO("fw upgrade in process, can't suspend"); - return 0; - } - -#if FTS_ESDCHECK_EN - fts_esdcheck_suspend(); -#endif - -#if FTS_GESTURE_EN - if (fts_gesture_suspend(ts_data) == 0) { - /* Enter into gesture mode(suspend) */ - ts_data->suspended = true; - return 0; - } -#endif - - - /* TP enter sleep mode */ - ret = fts_write_reg(FTS_REG_POWER_MODE, FTS_REG_POWER_MODE_SLEEP_VALUE); - if (ret < 0) - FTS_ERROR("set TP to sleep mode fail, ret=%d", ret); - - /* TP delay 50ms then lcd entery suspend*/ - mdelay(50); - - if (!ts_data->ic_info.is_incell) { -#if FTS_POWER_SOURCE_CUST_EN - ret = fts_power_source_suspend(ts_data); - if (ret < 0) { - FTS_ERROR("power enter suspend fail"); - } -#endif - } - - ts_data->suspended = true; - FTS_FUNC_EXIT(); - return 0; -} - -static int fts_ts_resume(struct device *dev) -{ - struct fts_ts_data *ts_data = fts_data; - - FTS_FUNC_ENTER(); - if (!ts_data->suspended) { - FTS_DEBUG("Already in awake state"); - return 0; - } - - fts_release_all_finger(); - - if (!ts_data->ic_info.is_incell) { -#if FTS_POWER_SOURCE_CUST_EN - fts_power_source_resume(ts_data); -#endif - //fts_reset_proc(200); - } - - fts_tp_state_recovery(ts_data); - -#if FTS_ESDCHECK_EN - fts_esdcheck_resume(); -#endif - -#if FTS_GESTURE_EN - if (fts_gesture_resume(ts_data) == 0) { - ts_data->suspended = false; - return 0; - } -#endif - - - ts_data->suspended = false; - FTS_FUNC_EXIT(); - return 0; -} - -/***************************************************************************** -* TP Driver -*****************************************************************************/ -static int fts_ts_probe(struct spi_device *spi) -{ - int ret = 0; - struct fts_ts_data *ts_data = NULL; - - FTS_INFO("Touch Screen(SPI BUS) driver prboe..."); -#if defined(CONFIG_INPUT_FOCALTECH_0FLASH_MMI_IC_NAME_FT8756) - spi->mode = SPI_MODE_0; -#elif defined(CONFIG_INPUT_FOCALTECH_0FLASH_MMI_IC_NAME_FT8719) - spi->mode = SPI_MODE_1; -#else - spi->mode = SPI_MODE_1; -#endif - - spi->bits_per_word = 8; - if (spi->max_speed_hz > FTS_SPI_CLK_MAX) - spi->max_speed_hz = FTS_SPI_CLK_MAX; - - ret = spi_setup(spi); - if (ret) { - FTS_ERROR("spi setup fail"); - return ret; - } - - /* malloc memory for global struct variable */ - ts_data = (struct fts_ts_data *)kzalloc(sizeof(*ts_data), GFP_KERNEL); - if (!ts_data) { - FTS_ERROR("allocate memory for fts_data fail"); - return -ENOMEM; - } - - fts_data = ts_data; - ts_data->spi = spi; - ts_data->dev = &spi->dev; - ts_data->log_level = 1; - spi_set_drvdata(spi, ts_data); - - ret = fts_ts_probe_entry(ts_data); - if (ret) { - FTS_ERROR("Touch Screen(SPI BUS) driver probe fail"); - kfree_safe(ts_data); - return ret; - } - - FTS_INFO("Touch Screen(SPI BUS) driver prboe successfully"); - return 0; -} - -static int fts_ts_remove(struct spi_device *spi) -{ - return fts_ts_remove_entry(spi_get_drvdata(spi)); -} - -static const struct spi_device_id fts_ts_id[] = { - {FTS_DRIVER_NAME, 0}, - {}, -}; -static const struct of_device_id fts_dt_match[] = { - {.compatible = "focaltech,fts", }, - {}, -}; -MODULE_DEVICE_TABLE(of, fts_dt_match); - -static struct spi_driver fts_ts_driver = { - .probe = fts_ts_probe, - .remove = fts_ts_remove, - .driver = { - .name = FTS_DRIVER_NAME, - .owner = THIS_MODULE, - .of_match_table = of_match_ptr(fts_dt_match), - }, - .id_table = fts_ts_id, -}; - -static int __init fts_ts_init(void) -{ - int ret = 0; - - FTS_FUNC_ENTER(); - ret = spi_register_driver(&fts_ts_driver); - if ( ret != 0 ) { - FTS_ERROR("Focaltech touch screen driver init failed!"); - } - FTS_FUNC_EXIT(); - return ret; -} - -static void __exit fts_ts_exit(void) -{ - spi_unregister_driver(&fts_ts_driver); -} - -module_init(fts_ts_init); -module_exit(fts_ts_exit); - -MODULE_AUTHOR("FocalTech Driver Team"); -MODULE_DESCRIPTION("FocalTech Touchscreen Driver"); -MODULE_LICENSE("GPL v2"); diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_core.h b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_core.h deleted file mode 100755 index b6d3b6f34061..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_core.h +++ /dev/null @@ -1,273 +0,0 @@ -/* - * - * FocalTech TouchScreen driver. - * - * Copyright (c) 2012-2019, Focaltech Ltd. All rights reserved. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ -/***************************************************************************** -* -* File Name: focaltech_core.h - -* Author: Focaltech Driver Team -* -* Created: 2016-08-08 -* -* Abstract: -* -* Reference: -* -*****************************************************************************/ - -#ifndef __LINUX_FOCALTECH_CORE_H__ -#define __LINUX_FOCALTECH_CORE_H__ -/***************************************************************************** -* Included header files -*****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "focaltech_common.h" - -/***************************************************************************** -* Private constant and macro definitions using #define -*****************************************************************************/ -#define FTS_MAX_POINTS_SUPPORT 10 /* constant value, can't be changed */ -#define FTS_MAX_KEYS 4 -#define FTS_KEY_DIM 10 -#define FTS_ONE_TCH_LEN 6 -#define FTS_TOUCH_DATA_LEN (FTS_MAX_POINTS_SUPPORT * FTS_ONE_TCH_LEN + 3) - -#define FTS_SPI_CLK_MAX 10000000 - -#define FTS_GESTURE_POINTS_MAX 6 -#define FTS_GESTURE_DATA_LEN (FTS_GESTURE_POINTS_MAX * 4 + 4) - -#define FTS_MAX_ID 0x0A -#define FTS_TOUCH_X_H_POS 3 -#define FTS_TOUCH_X_L_POS 4 -#define FTS_TOUCH_Y_H_POS 5 -#define FTS_TOUCH_Y_L_POS 6 -#define FTS_TOUCH_PRE_POS 7 -#define FTS_TOUCH_AREA_POS 8 -#define FTS_TOUCH_POINT_NUM 2 -#define FTS_TOUCH_EVENT_POS 3 -#define FTS_TOUCH_ID_POS 5 -#define FTS_COORDS_ARR_SIZE 4 -#define FTS_X_MIN_DISPLAY_DEFAULT 0 -#define FTS_Y_MIN_DISPLAY_DEFAULT 0 -#define FTS_X_MAX_DISPLAY_DEFAULT 720 -#define FTS_Y_MAX_DISPLAY_DEFAULT 1280 - -#define FTS_TOUCH_DOWN 0 -#define FTS_TOUCH_UP 1 -#define FTS_TOUCH_CONTACT 2 -#define EVENT_DOWN(flag) ((FTS_TOUCH_DOWN == flag) || (FTS_TOUCH_CONTACT == flag)) -#define EVENT_UP(flag) (FTS_TOUCH_UP == flag) -#define EVENT_NO_DOWN(data) (!data->point_num) - -#define FTX_MAX_COMPATIBLE_TYPE 4 -#define FTX_MAX_COMMMAND_LENGTH 16 - -/***************************************************************************** -* Private enumerations, structures and unions using typedef -*****************************************************************************/ -struct ftxxxx_proc { - struct proc_dir_entry *proc_entry; - u8 opmode; - u8 cmd_len; - u8 cmd[FTX_MAX_COMMMAND_LENGTH]; -}; - -struct fts_ts_platform_data { - u32 irq_gpio; - u32 irq_gpio_flags; - u32 reset_gpio; - u32 reset_gpio_flags; - bool have_key; - u32 key_number; - u32 keys[FTS_MAX_KEYS]; - u32 key_y_coords[FTS_MAX_KEYS]; - u32 key_x_coords[FTS_MAX_KEYS]; - u32 x_max; - u32 y_max; - u32 x_min; - u32 y_min; - u32 max_touch_number; -}; - -struct ts_event { - int x; /*x coordinate */ - int y; /*y coordinate */ - int p; /* pressure */ - int flag; /* touch event flag: 0 -- down; 1-- up; 2 -- contact */ - int id; /*touch ID */ - int area; -}; - -struct fts_ts_data { - struct i2c_client *client; - struct spi_device *spi; - struct device *dev; - struct input_dev *input_dev; - struct fts_ts_platform_data *pdata; - struct ts_ic_info ic_info; - struct workqueue_struct *ts_workqueue; - struct work_struct fwupg_work; - struct delayed_work esdcheck_work; - struct delayed_work prc_work; - struct work_struct resume_work; - struct ftxxxx_proc proc; - spinlock_t irq_lock; - struct mutex report_mutex; - struct mutex bus_lock; - int irq; - int log_level; - int fw_is_running; /* confirm fw is running when using spi:default 0 */ - bool suspended; - bool fw_loading; - bool force_reflash; - bool irq_disabled; - bool power_disabled; - bool glove_mode; - bool cover_mode; - bool charger_mode; - /* multi-touch */ - struct ts_event *events; - u8 *bus_tx_buf; - u8 *bus_rx_buf; - u8 *point_buf; - int pnt_buf_size; - int touchs; - int key_state; - int touch_point; - int point_num; - struct regulator *vdd; - struct regulator *vcc_i2c; -#if FTS_PINCTRL_EN - struct pinctrl *pinctrl; - struct pinctrl_state *pins_active; - struct pinctrl_state *pins_suspend; - struct pinctrl_state *pins_release; -#endif -#if defined(CONFIG_FB) || defined(CONFIG_DRM) - struct notifier_block fb_notif; -#elif defined(CONFIG_HAS_EARLYSUSPEND) - struct early_suspend early_suspend; -#endif -}; - -/***************************************************************************** -* Global variable or extern global variabls/functions -*****************************************************************************/ -extern struct fts_ts_data *fts_data; - -/* communication interface */ -int fts_read(u8 *cmd, u32 cmdlen, u8 *data, u32 datalen); -int fts_read_reg(u8 addr, u8 *value); -int fts_write(u8 *writebuf, u32 writelen); -int fts_write_reg(u8 addr, u8 value); -void fts_hid2std(void); -int fts_bus_init(struct fts_ts_data *ts_data); -int fts_bus_exit(struct fts_ts_data *ts_data); - -/* Gesture functions */ -#if FTS_GESTURE_EN -int fts_gesture_init(struct fts_ts_data *ts_data); -int fts_gesture_exit(struct fts_ts_data *ts_data); -void fts_gesture_recovery(struct fts_ts_data *ts_data); -int fts_gesture_readdata(struct fts_ts_data *ts_data, u8 *data); -int fts_gesture_suspend(struct fts_ts_data *ts_data); -int fts_gesture_resume(struct fts_ts_data *ts_data); -#endif - -/* Apk and functions */ -#if FTS_APK_NODE_EN -int fts_create_apk_debug_channel(struct fts_ts_data *); -void fts_release_apk_debug_channel(struct fts_ts_data *); -#endif - -/* ADB functions */ -#if FTS_SYSFS_NODE_EN -int fts_create_sysfs(struct fts_ts_data *ts_data); -int fts_remove_sysfs(struct fts_ts_data *ts_data); -#endif - -/* ESD */ -#if FTS_ESDCHECK_EN -int fts_esdcheck_init(struct fts_ts_data *ts_data); -int fts_esdcheck_exit(struct fts_ts_data *ts_data); -int fts_esdcheck_switch(bool enable); -int fts_esdcheck_proc_busy(bool proc_debug); -int fts_esdcheck_set_intr(bool intr); -int fts_esdcheck_suspend(void); -int fts_esdcheck_resume(void); -#endif - -/* Production test */ -#if FTS_TEST_EN -int fts_test_init(struct fts_ts_data *ts_data); -int fts_test_exit(struct fts_ts_data *ts_data); -#endif - -/* Point Report Check*/ -#if FTS_POINT_REPORT_CHECK_EN -int fts_point_report_check_init(struct fts_ts_data *ts_data); -int fts_point_report_check_exit(struct fts_ts_data *ts_data); -void fts_prc_queue_work(struct fts_ts_data *ts_data); -#endif - -/* FW upgrade */ -int fts_fwupg_init(struct fts_ts_data *ts_data); -int fts_fwupg_exit(struct fts_ts_data *ts_data); -int fts_fw_recovery(void); -int fts_upgrade_bin(char *fw_name, bool force); -int fts_enter_test_environment(bool test_state); -int fts_fw_update_vendor_name(const char* name); - -/* Other */ -int fts_reset_proc(int hdelayms); -int fts_wait_tp_to_valid(void); -void fts_release_all_finger(void); -void fts_tp_state_recovery(struct fts_ts_data *ts_data); -int fts_ex_mode_init(struct fts_ts_data *ts_data); -int fts_ex_mode_exit(struct fts_ts_data *ts_data); -int fts_ex_mode_recovery(struct fts_ts_data *ts_data); - -void fts_irq_disable(void); -void fts_irq_enable(void); -#endif /* __LINUX_FOCALTECH_CORE_H__ */ diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_esdcheck.c b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_esdcheck.c deleted file mode 100755 index efd595fbcb14..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_esdcheck.c +++ /dev/null @@ -1,464 +0,0 @@ -/* - * - * FocalTech TouchScreen driver. - * - * Copyright (c) 2012-2019, FocalTech Systems, Ltd., all rights reserved. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/***************************************************************************** -* -* File Name: focaltech_esdcheck.c -* -* Author: Focaltech Driver Team -* -* Created: 2016-08-03 -* -* Abstract: ESD check function -* -* Version: v1.0 -* -* Revision History: -* v1.0: -* First release. By luougojin 2016-08-03 -* v1.1: By luougojin 2017-02-15 -* 1. Add LCD_ESD_PATCH to control idc_esdcheck_lcderror -*****************************************************************************/ - -/***************************************************************************** -* Included header files -*****************************************************************************/ -#include "focaltech_core.h" - -#if FTS_ESDCHECK_EN -/***************************************************************************** -* Private constant and macro definitions using #define -*****************************************************************************/ -#define ESDCHECK_WAIT_TIME 1000 /* ms */ -#define LCD_ESD_PATCH 0 - -/***************************************************************************** -* Private enumerations, structures and unions using typedef -*****************************************************************************/ -struct fts_esdcheck_st { - u8 mode : 1; /* 1- need check esd 0- no esd check */ - u8 suspend : 1; - u8 proc_debug : 1; /* apk or adb use */ - u8 intr : 1; /* 1- Interrupt trigger */ - u8 unused : 4; - u8 flow_work_hold_cnt; /* Flow Work Cnt(reg0x91) keep a same value for x times. >=5 times is ESD, need reset */ - u8 flow_work_cnt_last; /* Save Flow Work Cnt(reg0x91) value */ - u32 hardware_reset_cnt; - u32 nack_cnt; - u32 dataerror_cnt; -}; - -/***************************************************************************** -* Static variables -*****************************************************************************/ -static struct fts_esdcheck_st fts_esdcheck_data; - -/***************************************************************************** -* Global variable or extern global variabls/functions -*****************************************************************************/ - -/***************************************************************************** -* Static function prototypes -*****************************************************************************/ - -/***************************************************************************** -* functions body -*****************************************************************************/ -#if LCD_ESD_PATCH -int lcd_need_reset; -static int tp_need_recovery; /* LCD reset cause Tp reset */ -int idc_esdcheck_lcderror(struct fts_ts_data *ts_data) -{ - int ret = 0; - u8 val = 0; - - FTS_DEBUG("[ESD]Check LCD ESD"); - if ( (tp_need_recovery == 1) && (lcd_need_reset == 0) ) { - tp_need_recovery = 0; - /* LCD reset, need recover TP state */ - fts_release_all_finger(); - fts_tp_state_recovery(ts_data); - } - - ret = fts_read_reg(FTS_REG_ESD_SATURATE, &val); - if ( ret < 0) { - FTS_ERROR("[ESD]: Read ESD_SATURATE(0xED) failed ret=%d!", ret); - return -EIO; - } - - if (val == 0xAA) { - /* - * 1. Set flag lcd_need_reset = 1; - * 2. LCD driver need reset(recovery) LCD and set lcd_need_reset to 0 - * 3. recover TP state - */ - FTS_INFO("LCD ESD, Execute LCD reset!"); - lcd_need_reset = 1; - tp_need_recovery = 1; - } - - return 0; -} -#endif - -static int fts_esdcheck_tp_reset(struct fts_ts_data *ts_data) -{ - FTS_FUNC_ENTER(); - - fts_esdcheck_data.flow_work_hold_cnt = 0; - fts_esdcheck_data.hardware_reset_cnt++; - - fts_reset_proc(200); - fts_release_all_finger(); - fts_tp_state_recovery(ts_data); - - FTS_FUNC_EXIT(); - return 0; -} - -/***************************************************************************** -* Name: get_chip_id -* Brief: Read Chip Id 3 times -* Input: -* Output: -* Return: 1(ture) - Read Chip Id 3 times failed -* 0(false) - Read Chip Id pass -*****************************************************************************/ -static bool get_chip_id(struct fts_ts_data *ts_data) -{ - int ret = 0; - int i = 0; - u8 reg_value = 0; - u8 reg_addr = 0; - u8 chip_id = ts_data->ic_info.ids.chip_idh; - - for (i = 0; i < 3; i++) { - reg_addr = FTS_REG_CHIP_ID; - ret = fts_read(®_addr, 1, ®_value, 1); - if (ret < 0) { - FTS_ERROR("[ESD]: Read Reg 0xA3 failed ret = %d!!", ret); - fts_esdcheck_data.nack_cnt++; - } else { - if (reg_value == chip_id) { - break; - } else { - FTS_DEBUG("read chip_id:%x,retry:%d", reg_value, i); - fts_esdcheck_data.dataerror_cnt++; - } - } - msleep(10); - } - - /* if can't get correct data in 3 times, then need hardware reset */ - if (i >= 3) { - FTS_ERROR("[ESD]: Read Chip id 3 times failed, need execute TP reset!!"); - return true; - } - - return false; -} - -/***************************************************************************** -* Name: get_flow_cnt -* Brief: Read flow cnt(0x91) -* Input: -* Output: -* Return: 1(true) - Reg 0x91(flow cnt) abnormal: hold a value for 5 times -* 0(false) - Reg 0x91(flow cnt) normal -*****************************************************************************/ -static bool get_flow_cnt(struct fts_ts_data *ts_data) -{ - int ret = 0; - u8 reg_value = 0; - u8 reg_addr = 0; - - reg_addr = FTS_REG_FLOW_WORK_CNT; - ret = fts_read(®_addr, 1, ®_value, 1); - if (ret < 0) { - FTS_ERROR("[ESD]: Read Reg 0x91 failed ret = %d!!", ret); - fts_esdcheck_data.nack_cnt++; - } else { - if ( reg_value == fts_esdcheck_data.flow_work_cnt_last ) { - fts_esdcheck_data.flow_work_hold_cnt++; - } else { - fts_esdcheck_data.flow_work_hold_cnt = 0; - } - - fts_esdcheck_data.flow_work_cnt_last = reg_value; - } - - /* if read flow work cnt 5 times and the value are all the same, then need hardware_reset */ - if (fts_esdcheck_data.flow_work_hold_cnt >= 5) { - FTS_DEBUG("[ESD]: Flow Work Cnt(reg0x91) keep a value for 5 times, need execute TP reset!!"); - return true; - } - - return false; -} - -static int esdcheck_algorithm(struct fts_ts_data *ts_data) -{ - int ret = 0; - u8 reg_value = 0; - u8 reg_addr = 0; - bool hardware_reset = 0; - - /* 1. esdcheck is interrupt, then return */ - if (fts_esdcheck_data.intr == 1) { - FTS_DEBUG("[ESD]: In interrupt state, not check esd, return immediately!!"); - return 0; - } - - /* 2. check power state, if suspend, no need check esd */ - if (fts_esdcheck_data.suspend == 1) { - FTS_DEBUG("[ESD]: In suspend, not check esd, return immediately!!"); - /* because in suspend state, adb can be used, when upgrade FW, will active ESD check(active = 1) - * But in suspend, then will don't queue_delayed_work, when resume, don't check ESD again - */ - return 0; - } - - /* 3. check fts_esdcheck_data.proc_debug state, if 1-proc busy, no need check esd*/ - if (fts_esdcheck_data.proc_debug == 1) { - FTS_INFO("[ESD]: In apk or adb command mode, not check esd, return immediately!!"); - return 0; - } - - /* 4. In factory mode, can't check esd */ - reg_addr = FTS_REG_WORKMODE; - ret = fts_read_reg(reg_addr, ®_value); - if ( ret < 0 ) { - fts_esdcheck_data.nack_cnt++; - } else if ( (reg_value & 0x70) != FTS_REG_WORKMODE_WORK_VALUE) { - FTS_DEBUG("[ESD]: not in work mode, no check esd, return immediately!!"); - return 0; - } - - /* 5. IDC esd check lcd default:close */ -#if LCD_ESD_PATCH - idc_esdcheck_lcderror(ts_data); -#endif - - /* 6. Get Chip ID */ - hardware_reset = get_chip_id(ts_data); - - /* 7. get Flow work cnt: 0x91 If no change for 5 times, then ESD and reset */ - if (!hardware_reset) { - hardware_reset = get_flow_cnt(ts_data); - } - - /* 8. If need hardware reset, then handle it here */ - if ( hardware_reset == 1) { - FTS_DEBUG("[ESD]: NoACK=%d, Error Data=%d, Hardware Reset=%d", \ - fts_esdcheck_data.nack_cnt, fts_esdcheck_data.dataerror_cnt, \ - fts_esdcheck_data.hardware_reset_cnt); - fts_esdcheck_tp_reset(ts_data); - } - - return 0; -} - -static void esdcheck_func(struct work_struct *work) -{ - u8 val = 0; - struct fts_ts_data *ts_data = container_of(work, - struct fts_ts_data, esdcheck_work.work); - - if (ENABLE == fts_esdcheck_data.mode) { - if (ts_data->ic_info.is_incell) { - fts_read_reg(FTS_REG_ESDCHECK_DISABLE, &val); - if (0xA5 == val) { - fts_esdcheck_data.mode = DISABLE; - return; - } - } - esdcheck_algorithm(ts_data); - queue_delayed_work(ts_data->ts_workqueue, &ts_data->esdcheck_work, - msecs_to_jiffies(ESDCHECK_WAIT_TIME)); - } - -} - -int fts_esdcheck_set_intr(bool intr) -{ - /* interrupt don't add debug message */ - fts_esdcheck_data.intr = intr; - return 0; -} - -int fts_esdcheck_get_status(void) -{ - /* interrupt don't add debug message */ - return fts_esdcheck_data.mode; -} - -/***************************************************************************** -* Name: fts_esdcheck_proc_busy -* Brief: When APK or ADB command access TP via driver, then need set proc_debug, -* then will not check ESD. -* Input: -* Output: -* Return: -*****************************************************************************/ -int fts_esdcheck_proc_busy(bool proc_debug) -{ - fts_esdcheck_data.proc_debug = proc_debug; - return 0; -} - -/***************************************************************************** -* Name: fts_esdcheck_switch -* Brief: FTS esd check function switch. -* Input: enable: 1 - Enable esd check -* 0 - Disable esd check -* Output: -* Return: -*****************************************************************************/ -int fts_esdcheck_switch(bool enable) -{ - struct fts_ts_data *ts_data = fts_data; - FTS_FUNC_ENTER(); - if (fts_esdcheck_data.mode == ENABLE) { - if (enable) { - FTS_DEBUG("[ESD]: ESD check start!!"); - fts_esdcheck_data.flow_work_hold_cnt = 0; - fts_esdcheck_data.flow_work_cnt_last = 0; - queue_delayed_work(ts_data->ts_workqueue, &ts_data->esdcheck_work, - msecs_to_jiffies(ESDCHECK_WAIT_TIME)); - } else { - FTS_DEBUG("[ESD]: ESD check stop!!"); - cancel_delayed_work_sync(&ts_data->esdcheck_work); - } - } else { - FTS_DEBUG("[ESD]: ESD should disable!!"); - cancel_delayed_work_sync(&ts_data->esdcheck_work); - } - - FTS_FUNC_EXIT(); - return 0; -} - -int fts_esdcheck_suspend(void) -{ - FTS_FUNC_ENTER(); - fts_esdcheck_switch(DISABLE); - fts_esdcheck_data.suspend = 1; - FTS_FUNC_EXIT(); - return 0; -} - -int fts_esdcheck_resume( void ) -{ - FTS_FUNC_ENTER(); - fts_esdcheck_switch(ENABLE); - fts_esdcheck_data.suspend = 0; - FTS_FUNC_EXIT(); - return 0; -} - -static ssize_t fts_esdcheck_store( - struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - struct input_dev *input_dev = fts_data->input_dev; - - mutex_lock(&input_dev->mutex); - if (FTS_SYSFS_ECHO_ON(buf)) { - FTS_DEBUG("enable esdcheck"); - fts_esdcheck_data.mode = ENABLE; - fts_esdcheck_switch(ENABLE); - } else if (FTS_SYSFS_ECHO_OFF(buf)) { - FTS_DEBUG("disable esdcheck"); - fts_esdcheck_data.mode = DISABLE; - fts_esdcheck_switch(DISABLE); - } - mutex_unlock(&input_dev->mutex); - - return count; -} - -static ssize_t fts_esdcheck_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - int count; - struct input_dev *input_dev = fts_data->input_dev; - - mutex_lock(&input_dev->mutex); - count = snprintf(buf, PAGE_SIZE, "Esd check: %s\n", \ - fts_esdcheck_get_status() ? "On" : "Off"); - mutex_unlock(&input_dev->mutex); - - return count; -} - -/* sysfs esd node - * read example: cat fts_esd_mode ---read esd mode - * write example:echo 01 > fts_esd_mode ---make esdcheck enable - * - */ -static DEVICE_ATTR (fts_esd_mode, S_IRUGO | S_IWUSR, fts_esdcheck_show, fts_esdcheck_store); - -static struct attribute *fts_esd_mode_attrs[] = { - - &dev_attr_fts_esd_mode.attr, - NULL, -}; - -static struct attribute_group fts_esd_group = { - .attrs = fts_esd_mode_attrs, -}; - -int fts_create_esd_sysfs(struct device *dev) -{ - int ret = 0; - - ret = sysfs_create_group(&dev->kobj, &fts_esd_group); - if ( ret != 0) { - FTS_ERROR("fts_create_esd_sysfs(sysfs) create failed!"); - sysfs_remove_group(&dev->kobj, &fts_esd_group); - return ret; - } - return 0; -} - -int fts_esdcheck_init(struct fts_ts_data *ts_data) -{ - FTS_FUNC_ENTER(); - - if (ts_data->ts_workqueue) { - INIT_DELAYED_WORK(&ts_data->esdcheck_work, esdcheck_func); - } else { - FTS_ERROR("fts workqueue is NULL, can't run esd check function"); - return -EINVAL; - } - - memset((u8 *)&fts_esdcheck_data, 0, sizeof(struct fts_esdcheck_st)); - - fts_esdcheck_data.mode = ENABLE; - fts_esdcheck_switch(ENABLE); - fts_create_esd_sysfs(ts_data->dev); - FTS_FUNC_EXIT(); - return 0; -} - -int fts_esdcheck_exit(struct fts_ts_data *ts_data) -{ - sysfs_remove_group(&ts_data->dev->kobj, &fts_esd_group); - return 0; -} -#endif /* FTS_ESDCHECK_EN */ - diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_ex_fun.c b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_ex_fun.c deleted file mode 100755 index 9a2e96ed0e05..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_ex_fun.c +++ /dev/null @@ -1,1433 +0,0 @@ -/* - * - * FocalTech TouchScreen driver. - * - * Copyright (c) 2012-2019, Focaltech Ltd. All rights reserved. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/***************************************************************************** -* -* File Name: Focaltech_ex_fun.c -* -* Author: Focaltech Driver Team -* -* Created: 2016-08-08 -* -* Abstract: -* -* Reference: -* -*****************************************************************************/ - -/***************************************************************************** -* 1.Included header files -*****************************************************************************/ -#include "focaltech_core.h" - -/***************************************************************************** -* Private constant and macro definitions using #define -*****************************************************************************/ -#define PROC_UPGRADE 0 -#define PROC_READ_REGISTER 1 -#define PROC_WRITE_REGISTER 2 -#define PROC_AUTOCLB 4 -#define PROC_UPGRADE_INFO 5 -#define PROC_WRITE_DATA 6 -#define PROC_READ_DATA 7 -#define PROC_SET_TEST_FLAG 8 -#define PROC_SET_SLAVE_ADDR 10 -#define PROC_HW_RESET 11 -#define PROC_READ_STATUS 12 -#define PROC_SET_BOOT_MODE 13 -#define PROC_ENTER_TEST_ENVIRONMENT 14 -#define PROC_NAME "ftxxxx-debug" -#define PROC_BUF_SIZE 256 - -/***************************************************************************** -* Private enumerations, structures and unions using typedef -*****************************************************************************/ -enum { - RWREG_OP_READ = 0, - RWREG_OP_WRITE = 1, -}; - -/***************************************************************************** -* Static variables -*****************************************************************************/ -static struct rwreg_operation_t { - int type; /* 0: read, 1: write */ - int reg; /* register */ - int len; /* read/write length */ - int val; /* length = 1; read: return value, write: op return */ - int res; /* 0: success, otherwise: fail */ - char *opbuf; /* length >= 1, read return value, write: op return */ -} rw_op; - -/***************************************************************************** -* Global variable or extern global variabls/functions -*****************************************************************************/ - -/***************************************************************************** -* Static function prototypes -*****************************************************************************/ -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)) -static ssize_t fts_debug_write( - struct file *filp, const char __user *buff, size_t count, loff_t *ppos) -{ - u8 *writebuf = NULL; - u8 tmpbuf[PROC_BUF_SIZE] = { 0 }; - int buflen = count; - int writelen = 0; - int ret = 0; - char tmp[PROC_BUF_SIZE]; - struct fts_ts_data *ts_data = fts_data; - struct ftxxxx_proc *proc = &ts_data->proc; - - if ((buflen <= 1) || (buflen > PAGE_SIZE)) { - FTS_ERROR("apk proc wirte count(%d>%d) fail", buflen, (int)PAGE_SIZE); - return -EINVAL; - } - - if (buflen > PROC_BUF_SIZE) { - writebuf = (u8 *)kzalloc(buflen * sizeof(u8), GFP_KERNEL); - if (NULL == writebuf) { - FTS_ERROR("apk proc wirte buf zalloc fail"); - return -ENOMEM; - } - } else { - writebuf = tmpbuf; - } - - if (copy_from_user(writebuf, buff, buflen)) { - FTS_ERROR("[APK]: copy from user error!!"); - ret = -EFAULT; - goto proc_write_err; - } - - proc->opmode = writebuf[0]; - switch (proc->opmode) { - case PROC_SET_TEST_FLAG: - FTS_DEBUG("[APK]: PROC_SET_TEST_FLAG = %x", writebuf[1]); - if (writebuf[1] == 0) { -#if FTS_ESDCHECK_EN - fts_esdcheck_switch(ENABLE); -#endif - } else { -#if FTS_ESDCHECK_EN - fts_esdcheck_switch(DISABLE); -#endif - } - break; - - case PROC_READ_REGISTER: - proc->cmd[0] = writebuf[1]; - break; - - case PROC_WRITE_REGISTER: - ret = fts_write_reg(writebuf[1], writebuf[2]); - if (ret < 0) { - FTS_ERROR("PROC_WRITE_REGISTER write error"); - goto proc_write_err; - } - break; - - case PROC_READ_DATA: - writelen = buflen - 1; - memcpy(proc->cmd, writebuf + 1, writelen); - proc->cmd_len = writelen; - break; - - case PROC_WRITE_DATA: - writelen = buflen - 1; - ret = fts_write(writebuf + 1, writelen); - if (ret < 0) { - FTS_ERROR("PROC_WRITE_DATA write error"); - goto proc_write_err; - } - break; - - case PROC_SET_SLAVE_ADDR: - break; - - case PROC_HW_RESET: - snprintf(tmp, PROC_BUF_SIZE, "%s", writebuf + 1); - tmp[buflen - 1] = '\0'; - if (strncmp(tmp, "focal_driver", 12) == 0) { - FTS_INFO("APK execute HW Reset"); - fts_reset_proc(0); - } - break; - - case PROC_SET_BOOT_MODE: - FTS_DEBUG("[APK]: PROC_SET_BOOT_MODE = %x", writebuf[1]); - if (0 == writebuf[1]) { - ts_data->fw_is_running = true; - } else { - ts_data->fw_is_running = false; - } - break; - case PROC_ENTER_TEST_ENVIRONMENT: - FTS_DEBUG("[APK]: PROC_ENTER_TEST_ENVIRONMENT = %x", writebuf[1]); - if (0 == writebuf[1]) { - fts_enter_test_environment(0); - } else { - fts_enter_test_environment(1); - } - break; - - default: - break; - } - - ret = buflen; -proc_write_err: - if ((buflen > PROC_BUF_SIZE) && writebuf) { - kfree(writebuf); - writebuf = NULL; - } - return ret; -} - -static ssize_t fts_debug_read( - struct file *filp, char __user *buff, size_t count, loff_t *ppos) -{ - int ret = 0; - int num_read_chars = 0; - int buflen = count; - u8 *readbuf = NULL; - u8 tmpbuf[PROC_BUF_SIZE] = { 0 }; - struct fts_ts_data *ts_data = fts_data; - struct ftxxxx_proc *proc = &ts_data->proc; - - if ((buflen <= 0) || (buflen > PAGE_SIZE)) { - FTS_ERROR("apk proc read count(%d>%d) fail", buflen, (int)PAGE_SIZE); - return -EINVAL; - } - - if (buflen > PROC_BUF_SIZE) { - readbuf = (u8 *)kzalloc(buflen * sizeof(u8), GFP_KERNEL); - if (NULL == readbuf) { - FTS_ERROR("apk proc wirte buf zalloc fail"); - return -ENOMEM; - } - } else { - readbuf = tmpbuf; - } - -#if FTS_ESDCHECK_EN - fts_esdcheck_proc_busy(1); -#endif - - switch (proc->opmode) { - case PROC_READ_REGISTER: - num_read_chars = 1; - ret = fts_read_reg(proc->cmd[0], &readbuf[0]); - if (ret < 0) { - FTS_ERROR("PROC_READ_REGISTER read error"); - goto proc_read_err; - } - break; - case PROC_WRITE_REGISTER: - break; - - case PROC_READ_DATA: - num_read_chars = buflen; - ret = fts_read(proc->cmd, proc->cmd_len, readbuf, num_read_chars); - if (ret < 0) { - FTS_ERROR("PROC_READ_DATA read error"); - goto proc_read_err; - } - break; - - case PROC_WRITE_DATA: - break; - - default: - break; - } - -#if FTS_ESDCHECK_EN - fts_esdcheck_proc_busy(0); -#endif - - if (copy_to_user(buff, readbuf, num_read_chars)) { - FTS_ERROR("copy to user error"); - ret = -EFAULT; - goto proc_read_err; - } - - ret = num_read_chars; -proc_read_err: - if ((buflen > PROC_BUF_SIZE) && readbuf) { - kfree(readbuf); - readbuf = NULL; - } - return ret; -} - -static const struct file_operations fts_proc_fops = { - .owner = THIS_MODULE, - .read = fts_debug_read, - .write = fts_debug_write, -}; -#else -static int fts_debug_write( - struct file *filp, const char __user *buff, unsigned long len, void *data) -{ - u8 *writebuf = NULL; - u8 tmpbuf[PROC_BUF_SIZE] = { 0 }; - int buflen = count; - int writelen = 0; - int ret = 0; - char tmp[PROC_BUF_SIZE]; - struct fts_ts_data *ts_data = fts_data; - struct ftxxxx_proc *proc = &ts_data->proc; - - if ((buflen <= 1) || (buflen > PAGE_SIZE)) { - FTS_ERROR("apk proc wirte count(%d>%d) fail", buflen, (int)PAGE_SIZE); - return -EINVAL; - } - - if (buflen > PROC_BUF_SIZE) { - writebuf = (u8 *)kzalloc(buflen * sizeof(u8), GFP_KERNEL); - if (NULL == writebuf) { - FTS_ERROR("apk proc wirte buf zalloc fail"); - return -ENOMEM; - } - } else { - writebuf = tmpbuf; - } - - if (copy_from_user(writebuf, buff, buflen)) { - FTS_ERROR("[APK]: copy from user error!!"); - ret = -EFAULT; - goto proc_write_err; - } - - proc->opmode = writebuf[0]; - switch (proc->opmode) { - case PROC_SET_TEST_FLAG: - FTS_DEBUG("[APK]: PROC_SET_TEST_FLAG = %x", writebuf[1]); - if (writebuf[1] == 0) { -#if FTS_ESDCHECK_EN - fts_esdcheck_switch(ENABLE); -#endif - } else { -#if FTS_ESDCHECK_EN - fts_esdcheck_switch(DISABLE); -#endif - } - break; - - case PROC_READ_REGISTER: - proc->cmd[0] = writebuf[1]; - break; - - case PROC_WRITE_REGISTER: - ret = fts_write_reg(writebuf[1], writebuf[2]); - if (ret < 0) { - FTS_ERROR("PROC_WRITE_REGISTER write error"); - goto proc_write_err; - } - break; - - case PROC_READ_DATA: - writelen = buflen - 1; - memcpy(proc->cmd, writebuf + 1, writelen); - proc->cmd_len = writelen; - break; - - case PROC_WRITE_DATA: - writelen = buflen - 1; - ret = fts_write(writebuf + 1, writelen); - if (ret < 0) { - FTS_ERROR("PROC_WRITE_DATA write error"); - goto proc_write_err; - } - break; - - case PROC_SET_SLAVE_ADDR: - break; - - case PROC_HW_RESET: - snprintf(tmp, PROC_BUF_SIZE, "%s", writebuf + 1); - tmp[buflen - 1] = '\0'; - if (strncmp(tmp, "focal_driver", 12) == 0) { - FTS_INFO("APK execute HW Reset"); - fts_reset_proc(0); - } - break; - - case PROC_SET_BOOT_MODE: - FTS_DEBUG("[APK]: PROC_SET_BOOT_MODE = %x", writebuf[1]); - if (0 == writebuf[1]) { - ts_data->fw_is_running = true; - } else { - ts_data->fw_is_running = false; - } - break; - case PROC_ENTER_TEST_ENVIRONMENT: - FTS_DEBUG("[APK]: PROC_ENTER_TEST_ENVIRONMENT = %x", writebuf[1]); - if (0 == writebuf[1]) { - fts_enter_test_environment(0); - } else { - fts_enter_test_environment(1); - } - break; - - default: - break; - } - - ret = buflen; -proc_write_err: - if ((buflen > PROC_BUF_SIZE) && writebuf) { - kfree(writebuf); - writebuf = NULL; - } - return ret; -} - -static int fts_debug_read( - char *page, char **start, off_t off, int count, int *eof, void *data ) -{ - int ret = 0; - int num_read_chars = 0; - int buflen = count; - u8 *readbuf = NULL; - u8 tmpbuf[PROC_BUF_SIZE] = { 0 }; - struct fts_ts_data *ts_data = fts_data; - struct ftxxxx_proc *proc = &ts_data->proc; - - if ((buflen <= 0) || (buflen > PAGE_SIZE)) { - FTS_ERROR("apk proc read count(%d>%d) fail", buflen, (int)PAGE_SIZE); - return -EINVAL; - } - - if (buflen > PROC_BUF_SIZE) { - readbuf = (u8 *)kzalloc(buflen * sizeof(u8), GFP_KERNEL); - if (NULL == readbuf) { - FTS_ERROR("apk proc wirte buf zalloc fail"); - return -ENOMEM; - } - } else { - readbuf = tmpbuf; - } - -#if FTS_ESDCHECK_EN - fts_esdcheck_proc_busy(1); -#endif - - switch (proc->opmode) { - case PROC_READ_REGISTER: - num_read_chars = 1; - ret = fts_read_reg(proc->cmd[0], &readbuf[0]); - if (ret < 0) { - FTS_ERROR("PROC_READ_REGISTER read error"); - goto proc_read_err; - } - break; - case PROC_WRITE_REGISTER: - break; - - case PROC_READ_DATA: - num_read_chars = buflen; - ret = fts_read(proc->cmd, proc->cmd_len, readbuf, num_read_chars); - if (ret < 0) { - FTS_ERROR("PROC_READ_DATA read error"); - goto proc_read_err; - } - break; - - case PROC_WRITE_DATA: - break; - - default: - break; - } - -#if FTS_ESDCHECK_EN - fts_esdcheck_proc_busy(0); -#endif - - if (copy_to_user(buff, readbuf, num_read_chars)) { - FTS_ERROR("copy to user error"); - ret = -EFAULT; - goto proc_read_err; - } - - ret = num_read_chars; -proc_read_err: - if ((buflen > PROC_BUF_SIZE) && readbuf) { - kfree(readbuf); - readbuf = NULL; - } - return ret; -} -#endif - -int fts_create_apk_debug_channel(struct fts_ts_data *ts_data) -{ - struct ftxxxx_proc *proc = &ts_data->proc; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)) - proc->proc_entry = proc_create(PROC_NAME, 0777, NULL, &fts_proc_fops); - if (NULL == proc->proc_entry) { - FTS_ERROR("create proc entry fail"); - return -ENOMEM; - } -#else - proc->proc_entry = create_proc_entry(PROC_NAME, 0777, NULL); - if (NULL == proc->proc_entry) { - FTS_ERROR("create proc entry fail"); - return -ENOMEM; - } - proc->proc_entry->write_proc = fts_debug_write; - proc->proc_entry->read_proc = fts_debug_read; -#endif - - FTS_INFO("Create proc entry success!"); - return 0; -} - -void fts_release_apk_debug_channel(struct fts_ts_data *ts_data) -{ - struct ftxxxx_proc *proc = &ts_data->proc; - - if (proc->proc_entry) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0)) - proc_remove(proc->proc_entry); -#else - remove_proc_entry(PROC_NAME, NULL); -#endif - } -} - -/************************************************************************ - * sysfs interface - ***********************************************************************/ -/* fts_hw_reset interface */ -static ssize_t fts_hw_reset_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - struct input_dev *input_dev = fts_data->input_dev; - ssize_t count = 0; - - mutex_lock(&input_dev->mutex); - fts_reset_proc(0); - count = snprintf(buf, PAGE_SIZE, "hw reset executed\n"); - mutex_unlock(&input_dev->mutex); - - return count; -} - -static ssize_t fts_hw_reset_store( - struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - return -EPERM; -} - -static ssize_t reset_store( - struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - struct input_dev *input_dev = fts_data->input_dev; - - if ('1' != buf[0]) { - pr_err("Invalid argument for reset\n"); - return -EINVAL; - } - - mutex_lock(&input_dev->mutex); - fts_reset_proc(0); - mutex_unlock(&input_dev->mutex); - - return count; -} - -/* fts_irq interface */ -static ssize_t fts_irq_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - ssize_t count = 0; - struct irq_desc *desc = irq_to_desc(fts_data->irq); - - count = snprintf(buf, PAGE_SIZE, "irq_depth:%d\n", desc->depth); - - return count; -} - -static ssize_t fts_irq_store( - struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - struct input_dev *input_dev = fts_data->input_dev; - - mutex_lock(&input_dev->mutex); - if (FTS_SYSFS_ECHO_ON(buf)) { - FTS_INFO("enable irq"); - fts_irq_enable(); - } else if (FTS_SYSFS_ECHO_OFF(buf)) { - FTS_INFO("disable irq"); - fts_irq_disable(); - } - mutex_unlock(&input_dev->mutex); - return count; -} - -static ssize_t drv_irq_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - return scnprintf(buf, PAGE_SIZE, "%s\n", - fts_data->irq_disabled? "DISABLED" : "ENABLED"); -} - -static ssize_t drv_irq_store( - struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - struct input_dev *input_dev = fts_data->input_dev; - - mutex_lock(&input_dev->mutex); - if (FTS_SYSFS_ECHO_ON(buf)) { - FTS_INFO("enable irq"); - fts_irq_enable(); - } else if (FTS_SYSFS_ECHO_OFF(buf)) { - FTS_INFO("disable irq"); - fts_irq_disable(); - } - mutex_unlock(&input_dev->mutex); - return count; -} - -/* fts_boot_mode interface */ -static ssize_t fts_bootmode_store( - struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - struct input_dev *input_dev = fts_data->input_dev; - - FTS_FUNC_ENTER(); - mutex_lock(&input_dev->mutex); - if (FTS_SYSFS_ECHO_ON(buf)) { - FTS_INFO("[EX-FUN]set to boot mode"); - fts_data->fw_is_running = false; - } else if (FTS_SYSFS_ECHO_OFF(buf)) { - FTS_INFO("[EX-FUN]set to fw mode"); - fts_data->fw_is_running = true; - } - mutex_unlock(&input_dev->mutex); - FTS_FUNC_EXIT(); - - return count; -} - -static ssize_t fts_bootmode_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - ssize_t count = 0; - struct input_dev *input_dev = fts_data->input_dev; - - FTS_FUNC_ENTER(); - mutex_lock(&input_dev->mutex); - if (true == fts_data->fw_is_running) { - count = snprintf(buf, PAGE_SIZE, "tp is in fw mode\n"); - } else { - count = snprintf(buf, PAGE_SIZE, "tp is in boot mode\n"); - } - mutex_unlock(&input_dev->mutex); - FTS_FUNC_EXIT(); - - return count; -} - - -static ssize_t fts_poweron_show(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct fts_ts_data *data = fts_data; - struct input_dev *input_dev = data->input_dev; - bool val; - - mutex_lock(&input_dev->mutex); - val = data->power_disabled; - mutex_unlock(&input_dev->mutex); - - return scnprintf(buf, PAGE_SIZE, "%d\n", val == false); -} - - -static ssize_t fts_productinfo_show(struct device *dev, struct device_attribute *attr, char *buf) -{ - return scnprintf(buf, PAGE_SIZE, "%s\n", FTS_CHIP_NAME); -} - -/* fts_tpfwver interface */ -static ssize_t fts_tpfwver_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - struct fts_ts_data *ts_data = fts_data; - struct input_dev *input_dev = ts_data->input_dev; - ssize_t num_read_chars = 0; - u8 fwver = 0; - - mutex_lock(&input_dev->mutex); - -#if FTS_ESDCHECK_EN - fts_esdcheck_proc_busy(1); -#endif - fts_read_reg(FTS_REG_FW_VER, &fwver); -#if FTS_ESDCHECK_EN - fts_esdcheck_proc_busy(0); -#endif - if ((fwver == 0xFF) || (fwver == 0x00)) - num_read_chars = snprintf(buf, PAGE_SIZE, "get tp fw version fail!\n"); - else - num_read_chars = snprintf(buf, PAGE_SIZE, "%02x\n", fwver); - - mutex_unlock(&input_dev->mutex); - return num_read_chars; -} - -static ssize_t fts_tpfwver_store( - struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - return -EPERM; -} - -static ssize_t buildid_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - struct fts_ts_data *ts_data = fts_data; - struct input_dev *input_dev = ts_data->input_dev; - ssize_t num_read_chars = 0; - u8 fwver = 0; - - mutex_lock(&input_dev->mutex); - -#if FTS_ESDCHECK_EN - fts_esdcheck_proc_busy(1); -#endif - fts_read_reg(FTS_REG_FW_VER, &fwver); -#if FTS_ESDCHECK_EN - fts_esdcheck_proc_busy(0); -#endif - if ((fwver == 0xFF) || (fwver == 0x00)) - num_read_chars = snprintf(buf, PAGE_SIZE, "get tp fw version fail!\n"); - else - num_read_chars = snprintf(buf, PAGE_SIZE, "0000-%02x\n", fwver); - - mutex_unlock(&input_dev->mutex); - return num_read_chars; -} - -/* fts_rw_reg */ -static ssize_t fts_tprwreg_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - int count; - int i; - struct input_dev *input_dev = fts_data->input_dev; - - mutex_lock(&input_dev->mutex); - - if (rw_op.len < 0) { - count = snprintf(buf, PAGE_SIZE, "Invalid cmd line\n"); - } else if (rw_op.len == 1) { - if (RWREG_OP_READ == rw_op.type) { - if (rw_op.res == 0) { - count = snprintf(buf, PAGE_SIZE, "Read %02X: %02X\n", rw_op.reg, rw_op.val); - } else { - count = snprintf(buf, PAGE_SIZE, "Read %02X failed, ret: %d\n", rw_op.reg, rw_op.res); - } - } else { - if (rw_op.res == 0) { - count = snprintf(buf, PAGE_SIZE, "Write %02X, %02X success\n", rw_op.reg, rw_op.val); - } else { - count = snprintf(buf, PAGE_SIZE, "Write %02X failed, ret: %d\n", rw_op.reg, rw_op.res); - } - } - } else { - if (RWREG_OP_READ == rw_op.type) { - count = snprintf(buf, PAGE_SIZE, "Read Reg: [%02X]-[%02X]\n", rw_op.reg, rw_op.reg + rw_op.len); - count += snprintf(buf + count, PAGE_SIZE, "Result: "); - if (rw_op.res) { - count += snprintf(buf + count, PAGE_SIZE, "failed, ret: %d\n", rw_op.res); - } else { - if (rw_op.opbuf) { - for (i = 0; i < rw_op.len; i++) { - count += snprintf(buf + count, PAGE_SIZE, "%02X ", rw_op.opbuf[i]); - } - count += snprintf(buf + count, PAGE_SIZE, "\n"); - } - } - } else { - ; - count = snprintf(buf, PAGE_SIZE, "Write Reg: [%02X]-[%02X]\n", rw_op.reg, rw_op.reg + rw_op.len - 1); - count += snprintf(buf + count, PAGE_SIZE, "Write Data: "); - if (rw_op.opbuf) { - for (i = 1; i < rw_op.len; i++) { - count += snprintf(buf + count, PAGE_SIZE, "%02X ", rw_op.opbuf[i]); - } - count += snprintf(buf + count, PAGE_SIZE, "\n"); - } - if (rw_op.res) { - count += snprintf(buf + count, PAGE_SIZE, "Result: failed, ret: %d\n", rw_op.res); - } else { - count += snprintf(buf + count, PAGE_SIZE, "Result: success\n"); - } - } - /*if (rw_op.opbuf) { - kfree(rw_op.opbuf); - rw_op.opbuf = NULL; - }*/ - } - mutex_unlock(&input_dev->mutex); - - return count; -} - -static int shex_to_int(const char *hex_buf, int size) -{ - int i; - int base = 1; - int value = 0; - char single; - - for (i = size - 1; i >= 0; i--) { - single = hex_buf[i]; - - if ((single >= '0') && (single <= '9')) { - value += (single - '0') * base; - } else if ((single >= 'a') && (single <= 'z')) { - value += (single - 'a' + 10) * base; - } else if ((single >= 'A') && (single <= 'Z')) { - value += (single - 'A' + 10) * base; - } else { - return -EINVAL; - } - - base *= 16; - } - - return value; -} - - -static u8 shex_to_u8(const char *hex_buf, int size) -{ - return (u8)shex_to_int(hex_buf, size); -} -/* - * Format buf: - * [0]: '0' write, '1' read(reserved) - * [1-2]: addr, hex - * [3-4]: length, hex - * [5-6]...[n-(n+1)]: data, hex - */ -static int fts_parse_buf(const char *buf, size_t cmd_len) -{ - int length; - int i; - char *tmpbuf; - - rw_op.reg = shex_to_u8(buf + 1, 2); - length = shex_to_int(buf + 3, 2); - - if (buf[0] == '1') { - rw_op.len = length; - rw_op.type = RWREG_OP_READ; - FTS_DEBUG("read %02X, %d bytes", rw_op.reg, rw_op.len); - } else { - if (cmd_len < (length * 2 + 5)) { - pr_err("data invalided!\n"); - return -EINVAL; - } - FTS_DEBUG("write %02X, %d bytes", rw_op.reg, length); - - /* first byte is the register addr */ - rw_op.type = RWREG_OP_WRITE; - rw_op.len = length + 1; - } - - if (rw_op.len > 0) { - tmpbuf = (char *)kzalloc(rw_op.len, GFP_KERNEL); - if (!tmpbuf) { - FTS_ERROR("allocate memory failed!\n"); - return -ENOMEM; - } - - if (RWREG_OP_WRITE == rw_op.type) { - tmpbuf[0] = rw_op.reg & 0xFF; - FTS_DEBUG("write buffer: "); - for (i = 1; i < rw_op.len; i++) { - tmpbuf[i] = shex_to_u8(buf + 5 + i * 2 - 2, 2); - FTS_DEBUG("buf[%d]: %02X", i, tmpbuf[i] & 0xFF); - } - } - rw_op.opbuf = tmpbuf; - } - - return rw_op.len; -} - -static ssize_t fts_tprwreg_store( - struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - struct input_dev *input_dev = fts_data->input_dev; - ssize_t cmd_length = 0; - - mutex_lock(&input_dev->mutex); - cmd_length = count - 1; - - if (rw_op.opbuf) { - kfree(rw_op.opbuf); - rw_op.opbuf = NULL; - } - - FTS_DEBUG("cmd len: %d, buf: %s", (int)cmd_length, buf); - /* compatible old ops */ - if (2 == cmd_length) { - rw_op.type = RWREG_OP_READ; - rw_op.len = 1; - rw_op.reg = shex_to_int(buf, 2); - } else if (4 == cmd_length) { - rw_op.type = RWREG_OP_WRITE; - rw_op.len = 1; - rw_op.reg = shex_to_int(buf, 2); - rw_op.val = shex_to_int(buf + 2, 2); - } else if (cmd_length < 5) { - FTS_ERROR("Invalid cmd buffer"); - mutex_unlock(&input_dev->mutex); - return -EINVAL; - } else { - rw_op.len = fts_parse_buf(buf, cmd_length); - } - -#if FTS_ESDCHECK_EN - fts_esdcheck_proc_busy(1); -#endif - if (rw_op.len < 0) { - FTS_ERROR("cmd buffer error!"); - - } else { - if (RWREG_OP_READ == rw_op.type) { - if (rw_op.len == 1) { - u8 reg, val; - reg = rw_op.reg & 0xFF; - rw_op.res = fts_read_reg(reg, &val); - rw_op.val = val; - } else { - char reg; - reg = rw_op.reg & 0xFF; - - rw_op.res = fts_read(®, 1, rw_op.opbuf, rw_op.len); - } - - if (rw_op.res < 0) { - FTS_ERROR("Could not read 0x%02x", rw_op.reg); - } else { - FTS_INFO("read 0x%02x, %d bytes successful", rw_op.reg, rw_op.len); - rw_op.res = 0; - } - - } else { - if (rw_op.len == 1) { - u8 reg, val; - reg = rw_op.reg & 0xFF; - val = rw_op.val & 0xFF; - rw_op.res = fts_write_reg(reg, val); - } else { - rw_op.res = fts_write(rw_op.opbuf, rw_op.len); - } - if (rw_op.res < 0) { - FTS_ERROR("Could not write 0x%02x", rw_op.reg); - - } else { - FTS_INFO("Write 0x%02x, %d bytes successful", rw_op.val, rw_op.len); - rw_op.res = 0; - } - } - } - -#if FTS_ESDCHECK_EN - fts_esdcheck_proc_busy(0); -#endif - mutex_unlock(&input_dev->mutex); - - return count; -} - -/* fts_upgrade_bin interface */ -static ssize_t fts_fwupgradebin_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - return -EPERM; -} - -static ssize_t fts_fwupgradebin_store( - struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - char fwname[FILE_NAME_LENGTH] = { 0 }; - struct input_dev *input_dev = fts_data->input_dev; - - if ((count <= 1) || (count >= FILE_NAME_LENGTH - 32)) { - FTS_ERROR("fw bin name's length(%d) fail", (int)count); - return -EINVAL; - } - memset(fwname, 0, sizeof(fwname)); - snprintf(fwname, FILE_NAME_LENGTH, "%s", buf); - fwname[count - 1] = '\0'; - - FTS_INFO("upgrade with bin file through sysfs node"); - mutex_lock(&input_dev->mutex); - fts_upgrade_bin(fwname, 0); - mutex_unlock(&input_dev->mutex); - - return count; -} - -/* fts_force_upgrade interface */ -static ssize_t fts_fwforceupg_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - return -EPERM; -} - -static ssize_t fts_fwforceupg_store( - struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - char fwname[FILE_NAME_LENGTH]; - struct input_dev *input_dev = fts_data->input_dev; - - if ((count <= 1) || (count >= FILE_NAME_LENGTH - 32)) { - FTS_ERROR("fw bin name's length(%d) fail", (int)count); - return -EINVAL; - } - memset(fwname, 0, sizeof(fwname)); - snprintf(fwname, FILE_NAME_LENGTH, "%s", buf); - fwname[count - 1] = '\0'; - - FTS_INFO("force upgrade through sysfs node"); - mutex_lock(&input_dev->mutex); - fts_upgrade_bin(fwname, 1); - mutex_unlock(&input_dev->mutex); - - return count; -} - -static ssize_t forcereflash_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - unsigned int input; - - if (kstrtouint(buf, 10, &input) != 0) - return -EINVAL; - - fts_data->force_reflash = (input == 0) ? false : true; - - return count; -} - -static ssize_t flashprog_show(struct device *dev, struct device_attribute *attr, char *buf) -{ - return scnprintf(buf, PAGE_SIZE, "%d\n", (fts_data->fw_loading) ? 1 : 0); -} - -static ssize_t doreflash_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - char fwname[FILE_NAME_LENGTH]; - char prefix[FILE_NAME_LENGTH] = "focaltech"; - char template[FILE_NAME_LENGTH]; - struct input_dev *input_dev = fts_data->input_dev; - - if (count > FILE_NAME_LENGTH) { - FTS_ERROR("%s: FW filename is too long\n", __func__); - return -EINVAL; - } - - if (!fts_data->force_reflash) { - if (strncmp(buf, prefix, strnlen(prefix, sizeof(prefix)))) { - FTS_ERROR("%s: FW does not belong to Focaltech\n", __func__); - return -EINVAL; - } - - snprintf(template, sizeof(template), "-%s-", FTS_CHIP_NAME); - if (!strnstr(buf + strnlen(prefix, sizeof(prefix)), template, count)) { - FTS_ERROR("%s: FW does not belong to %s\n", __func__, FTS_CHIP_NAME); - return -EINVAL; - } - } - - memset(fwname, 0, sizeof(fwname)); - snprintf(fwname, PAGE_SIZE, "%s", buf); - fwname[count - 1] = '\0'; - - mutex_lock(&input_dev->mutex); - fts_fw_update_vendor_name(fwname); - fts_fw_recovery(); - mutex_unlock(&input_dev->mutex); - fts_data->force_reflash = false; - - return count; -} - -/* fts_driver_info interface */ -static ssize_t fts_driverinfo_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - int count = 0; - struct fts_ts_data *ts_data = fts_data; - struct fts_ts_platform_data *pdata = ts_data->pdata; - struct input_dev *input_dev = ts_data->input_dev; - - mutex_lock(&input_dev->mutex); - count += snprintf(buf + count, PAGE_SIZE, "Driver Ver:%s\n", FTS_DRIVER_VERSION); - - count += snprintf(buf + count, PAGE_SIZE, "Resolution:(%d,%d)~(%d,%d)\n", - pdata->x_min, pdata->y_min, pdata->x_max, pdata->y_max); - - count += snprintf(buf + count, PAGE_SIZE, "Max Touchs:%d\n", pdata->max_touch_number); - - count += snprintf(buf + count, PAGE_SIZE, "reset gpio:%d,int gpio:%d,irq:%d\n", - pdata->reset_gpio, pdata->irq_gpio, ts_data->irq); - - count += snprintf(buf + count, PAGE_SIZE, "IC ID:0x%02x%02x\n", - ts_data->ic_info.ids.chip_idh, ts_data->ic_info.ids.chip_idl); - mutex_unlock(&input_dev->mutex); - - return count; -} - -static ssize_t fts_driverinfo_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - return -EPERM; -} - -/* fts_dump_reg interface */ -static ssize_t fts_dumpreg_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - int count = 0; - u8 val = 0; - struct input_dev *input_dev = fts_data->input_dev; - - mutex_lock(&input_dev->mutex); -#if FTS_ESDCHECK_EN - fts_esdcheck_proc_busy(1); -#endif - fts_read_reg(FTS_REG_POWER_MODE, &val); - count += snprintf(buf + count, PAGE_SIZE, "Power Mode:0x%02x\n", val); - - fts_read_reg(FTS_REG_FW_VER, &val); - count += snprintf(buf + count, PAGE_SIZE, "FW Ver:0x%02x\n", val); - - fts_read_reg(FTS_REG_LIC_VER, &val); - count += snprintf(buf + count, PAGE_SIZE, "LCD Initcode Ver:0x%02x\n", val); - - fts_read_reg(FTS_REG_IDE_PARA_VER_ID, &val); - count += snprintf(buf + count, PAGE_SIZE, "Param Ver:0x%02x\n", val); - - fts_read_reg(FTS_REG_IDE_PARA_STATUS, &val); - count += snprintf(buf + count, PAGE_SIZE, "Param status:0x%02x\n", val); - - fts_read_reg(FTS_REG_VENDOR_ID, &val); - count += snprintf(buf + count, PAGE_SIZE, "Vendor ID:0x%02x\n", val); - - fts_read_reg(FTS_REG_LCD_BUSY_NUM, &val); - count += snprintf(buf + count, PAGE_SIZE, "LCD Busy Number:0x%02x\n", val); - - fts_read_reg(FTS_REG_GESTURE_EN, &val); - count += snprintf(buf + count, PAGE_SIZE, "Gesture Mode:0x%02x\n", val); - - fts_read_reg(FTS_REG_CHARGER_MODE_EN, &val); - count += snprintf(buf + count, PAGE_SIZE, "charge stat:0x%02x\n", val); - - fts_read_reg(FTS_REG_INT_CNT, &val); - count += snprintf(buf + count, PAGE_SIZE, "INT count:0x%02x\n", val); - - fts_read_reg(FTS_REG_FLOW_WORK_CNT, &val); - count += snprintf(buf + count, PAGE_SIZE, "ESD count:0x%02x\n", val); -#if FTS_ESDCHECK_EN - fts_esdcheck_proc_busy(0); -#endif - - mutex_unlock(&input_dev->mutex); - - return count; -} - -static ssize_t fts_dumpreg_store( - struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - return -EPERM; -} - -/* fts_dump_reg interface */ -static ssize_t fts_tpbuf_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - int count = 0; - int i = 0; - struct input_dev *input_dev = fts_data->input_dev; - - mutex_lock(&input_dev->mutex); - count += snprintf(buf + count, PAGE_SIZE, "touch point buffer:\n"); - for (i = 0; i < fts_data->pnt_buf_size; i++) { - count += snprintf(buf + count, PAGE_SIZE, "%02x ", fts_data->point_buf[i]); - } - count += snprintf(buf + count, PAGE_SIZE, "\n"); - mutex_unlock(&input_dev->mutex); - - return count; -} - -static ssize_t fts_tpbuf_store( - struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - return -EPERM; -} - -/* fts_log_level interface */ -static ssize_t fts_log_level_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - int count = 0; - struct input_dev *input_dev = fts_data->input_dev; - - mutex_lock(&input_dev->mutex); - count += snprintf(buf + count, PAGE_SIZE, "log level:%d\n", - fts_data->log_level); - mutex_unlock(&input_dev->mutex); - - return count; -} - -static ssize_t fts_log_level_store( - struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - int value = 0; - struct input_dev *input_dev = fts_data->input_dev; - - FTS_FUNC_ENTER(); - mutex_lock(&input_dev->mutex); - sscanf(buf, "%d", &value); - FTS_DEBUG("log level:%d->%d", fts_data->log_level, value); - fts_data->log_level = value; - mutex_unlock(&input_dev->mutex); - FTS_FUNC_EXIT(); - - return count; -} - -/* get the fw version example:cat fw_version */ -static DEVICE_ATTR(fts_fw_version, S_IRUGO | S_IWUSR, fts_tpfwver_show, fts_tpfwver_store); - -/* read and write register(s) -* All data type is **HEX** -* Single Byte: -* read: echo 88 > rw_reg ---read register 0x88 -* write: echo 8807 > rw_reg ---write 0x07 into register 0x88 -* Multi-bytes: -* [0:rw-flag][1-2: reg addr, hex][3-4: length, hex][5-6...n-n+1: write data, hex] -* rw-flag: 0, write; 1, read -* read: echo 10005 > rw_reg ---read reg 0x00-0x05 -* write: echo 000050102030405 > rw_reg ---write reg 0x00-0x05 as 01,02,03,04,05 -* Get result: -* cat rw_reg -*/ -static DEVICE_ATTR(fts_rw_reg, S_IRUGO | S_IWUSR, fts_tprwreg_show, fts_tprwreg_store); -/* upgrade from fw bin file example:echo "*.bin" > fts_upgrade_bin */ -static DEVICE_ATTR(fts_upgrade_bin, S_IRUGO | S_IWUSR, fts_fwupgradebin_show, fts_fwupgradebin_store); -static DEVICE_ATTR(fts_force_upgrade, S_IRUGO | S_IWUSR, fts_fwforceupg_show, fts_fwforceupg_store); -static DEVICE_ATTR(fts_driver_info, S_IRUGO | S_IWUSR, fts_driverinfo_show, fts_driverinfo_store); -static DEVICE_ATTR(fts_dump_reg, S_IRUGO | S_IWUSR, fts_dumpreg_show, fts_dumpreg_store); -static DEVICE_ATTR(fts_hw_reset, S_IRUGO | S_IWUSR, fts_hw_reset_show, fts_hw_reset_store); -static DEVICE_ATTR(fts_irq, S_IRUGO | S_IWUSR, fts_irq_show, fts_irq_store); -static DEVICE_ATTR(fts_boot_mode, S_IRUGO | S_IWUSR, fts_bootmode_show, fts_bootmode_store); -static DEVICE_ATTR(fts_touch_point, S_IRUGO | S_IWUSR, fts_tpbuf_show, fts_tpbuf_store); -static DEVICE_ATTR(fts_log_level, S_IRUGO | S_IWUSR, fts_log_level_show, fts_log_level_store); -static DEVICE_ATTR(drv_irq, S_IRUGO | S_IWUSR, drv_irq_show, drv_irq_store); -static DEVICE_ATTR(reset, S_IWUSR | S_IWGRP, NULL, reset_store); -static DEVICE_ATTR(buildid, S_IRUGO, buildid_show, NULL); -static DEVICE_ATTR(forcereflash, S_IWUSR | S_IWGRP, NULL, forcereflash_store); -static DEVICE_ATTR(flashprog, S_IRUGO, flashprog_show, NULL); -static DEVICE_ATTR(doreflash, S_IWUSR | S_IWGRP, NULL, doreflash_store); -static DEVICE_ATTR(poweron, S_IRUGO, fts_poweron_show, NULL); -static DEVICE_ATTR(productinfo, S_IRUGO, fts_productinfo_show, NULL); - -/* add your attr in here*/ -static struct attribute *fts_attributes[] = { - &dev_attr_fts_fw_version.attr, - &dev_attr_fts_rw_reg.attr, - &dev_attr_fts_dump_reg.attr, - &dev_attr_fts_upgrade_bin.attr, - &dev_attr_fts_force_upgrade.attr, - &dev_attr_fts_driver_info.attr, - &dev_attr_fts_hw_reset.attr, - &dev_attr_fts_irq.attr, - &dev_attr_fts_boot_mode.attr, - &dev_attr_fts_touch_point.attr, - &dev_attr_fts_log_level.attr, - &dev_attr_drv_irq.attr, - &dev_attr_reset.attr, - &dev_attr_buildid.attr, - &dev_attr_forcereflash.attr, - &dev_attr_flashprog.attr, - &dev_attr_doreflash.attr, - &dev_attr_poweron.attr, - &dev_attr_productinfo.attr, - NULL -}; - -static struct attribute_group fts_attribute_group = { - .attrs = fts_attributes -}; - -#include -#include - -/* Attribute: path (RO) */ -static ssize_t path_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct fts_ts_data *data = dev_get_drvdata(dev); - ssize_t blen; - const char *path; - - if (!data) { - pr_err("cannot get fts_ts_data pointer\n"); - return (ssize_t)0; - } - path = kobject_get_path(&data->spi->dev.kobj, GFP_KERNEL); - blen = scnprintf(buf, PAGE_SIZE, "%s", path ? path : "na"); - kfree(path); - return blen; -} - -/* Attribute: vendor (RO) */ -static ssize_t vendor_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - return scnprintf(buf, PAGE_SIZE, "focaltech"); -} - -static struct device_attribute touchscreen_attributes[] = { - __ATTR_RO(path), - __ATTR_RO(vendor), - __ATTR_NULL -}; - -#define TSDEV_MINOR_BASE 128 -#define TSDEV_MINOR_MAX 32 - -static int fts_sysfs_class(void *_data, bool create) -{ - struct fts_ts_data *data = _data; - struct device_attribute *attrs = touchscreen_attributes; - int i, error = 0; - static struct class *touchscreen_class; - static struct device *ts_class_dev; - static int minor; - - if (create) { - minor = input_get_new_minor(data->spi->chip_select, - 1, false); - if (minor < 0) - minor = input_get_new_minor(TSDEV_MINOR_BASE, - TSDEV_MINOR_MAX, true); - pr_info("assigned minor %d\n", minor); - - touchscreen_class = class_create(THIS_MODULE, "touchscreen"); - if (IS_ERR(touchscreen_class)) { - error = PTR_ERR(touchscreen_class); - touchscreen_class = NULL; - return error; - } - - ts_class_dev = device_create(touchscreen_class, NULL, - MKDEV(INPUT_MAJOR, minor), - data, FTS_CHIP_NAME); - if (IS_ERR(ts_class_dev)) { - error = PTR_ERR(ts_class_dev); - ts_class_dev = NULL; - return error; - } - - for (i = 0; attrs[i].attr.name != NULL; ++i) { - error = device_create_file(ts_class_dev, &attrs[i]); - if (error) - break; - } - - if (error) - goto device_destroy; - } else { - if (!touchscreen_class || !ts_class_dev) - return -ENODEV; - - for (i = 0; attrs[i].attr.name != NULL; ++i) - device_remove_file(ts_class_dev, &attrs[i]); - - device_unregister(ts_class_dev); - class_unregister(touchscreen_class); - } - - return 0; - -device_destroy: - for (--i; i >= 0; --i) - device_remove_file(ts_class_dev, &attrs[i]); - device_destroy(touchscreen_class, MKDEV(INPUT_MAJOR, minor)); - ts_class_dev = NULL; - class_unregister(touchscreen_class); - pr_err("error creating touchscreen class\n"); - - return -ENODEV; -} - -int fts_create_sysfs(struct fts_ts_data *ts_data) -{ - int ret = 0; - - ret = sysfs_create_group(&ts_data->dev->kobj, &fts_attribute_group); - if (ret) { - FTS_ERROR("[EX]: sysfs_create_group() failed!!"); - sysfs_remove_group(&ts_data->dev->kobj, &fts_attribute_group); - return -ENOMEM; - } - ret = fts_sysfs_class(ts_data, true); - if (ret) { - FTS_ERROR("[EX]: fts_sysfs_class() failed!!"); - sysfs_remove_group(&ts_data->dev->kobj, &fts_attribute_group); - return -ENOMEM; - } - FTS_INFO("[EX]: sysfs_create_group() succeeded!!"); - - return ret; -} - -int fts_remove_sysfs(struct fts_ts_data *ts_data) -{ - sysfs_remove_group(&ts_data->dev->kobj, &fts_attribute_group); - fts_sysfs_class(ts_data, false); - return 0; -} diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_ex_mode.c b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_ex_mode.c deleted file mode 100755 index c0c970b12e48..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_ex_mode.c +++ /dev/null @@ -1,307 +0,0 @@ -/* - * - * FocalTech ftxxxx TouchScreen driver. - * - * Copyright (c) 2012-2019, Focaltech Ltd. All rights reserved. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/***************************************************************************** -* -* File Name: focaltech_ex_mode.c -* -* Author: Focaltech Driver Team -* -* Created: 2016-08-31 -* -* Abstract: -* -* Reference: -* -*****************************************************************************/ - -/***************************************************************************** -* 1.Included header files -*****************************************************************************/ -#include "focaltech_core.h" - -/***************************************************************************** -* 2.Private constant and macro definitions using #define -*****************************************************************************/ - -/***************************************************************************** -* 3.Private enumerations, structures and unions using typedef -*****************************************************************************/ -enum _ex_mode { - MODE_GLOVE = 0, - MODE_COVER, - MODE_CHARGER, -}; - -/***************************************************************************** -* 4.Static variables -*****************************************************************************/ - -/***************************************************************************** -* 5.Global variable or extern global variabls/functions -*****************************************************************************/ - -/***************************************************************************** -* 6.Static function prototypes -*******************************************************************************/ -static int fts_ex_mode_switch(enum _ex_mode mode, u8 value) -{ - int ret = 0; - u8 m_val = 0; - - if (value) - m_val = 0x01; - else - m_val = 0x00; - - switch (mode) { - case MODE_GLOVE: - ret = fts_write_reg(FTS_REG_GLOVE_MODE_EN, m_val); - if (ret < 0) { - FTS_ERROR("MODE_GLOVE switch to %d fail", m_val); - } - break; - case MODE_COVER: - ret = fts_write_reg(FTS_REG_COVER_MODE_EN, m_val); - if (ret < 0) { - FTS_ERROR("MODE_COVER switch to %d fail", m_val); - } - break; - case MODE_CHARGER: - ret = fts_write_reg(FTS_REG_CHARGER_MODE_EN, m_val); - if (ret < 0) { - FTS_ERROR("MODE_CHARGER switch to %d fail", m_val); - } - break; - default: - FTS_ERROR("mode(%d) unsupport", mode); - ret = -EINVAL; - break; - } - - return ret; -} - -static ssize_t fts_glove_mode_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - int count = 0; - u8 val = 0; - struct fts_ts_data *ts_data = fts_data; - struct input_dev *input_dev = ts_data->input_dev; - - mutex_lock(&input_dev->mutex); - fts_read_reg(FTS_REG_GLOVE_MODE_EN, &val); - count = snprintf(buf + count, PAGE_SIZE, "Glove Mode:%s\n", - ts_data->glove_mode ? "On" : "Off"); - count += snprintf(buf + count, PAGE_SIZE, "Glove Reg(0xC0):%d\n", val); - mutex_unlock(&input_dev->mutex); - - return count; -} - -static ssize_t fts_glove_mode_store( - struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - int ret = 0; - struct fts_ts_data *ts_data = fts_data; - - if (FTS_SYSFS_ECHO_ON(buf)) { - if (!ts_data->glove_mode) { - FTS_DEBUG("enter glove mode"); - ret = fts_ex_mode_switch(MODE_GLOVE, ENABLE); - if (ret >= 0) { - ts_data->glove_mode = ENABLE; - } - } - } else if (FTS_SYSFS_ECHO_OFF(buf)) { - if (ts_data->glove_mode) { - FTS_DEBUG("exit glove mode"); - ret = fts_ex_mode_switch(MODE_GLOVE, DISABLE); - if (ret >= 0) { - ts_data->glove_mode = DISABLE; - } - } - } - - FTS_DEBUG("glove mode:%d", ts_data->glove_mode); - return count; -} - - -static ssize_t fts_cover_mode_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - int count = 0; - u8 val = 0; - struct fts_ts_data *ts_data = fts_data; - struct input_dev *input_dev = ts_data->input_dev; - - mutex_lock(&input_dev->mutex); - fts_read_reg(FTS_REG_COVER_MODE_EN, &val); - count = snprintf(buf + count, PAGE_SIZE, "Cover Mode:%s\n", - ts_data->cover_mode ? "On" : "Off"); - count += snprintf(buf + count, PAGE_SIZE, "Cover Reg(0xC1):%d\n", val); - mutex_unlock(&input_dev->mutex); - - return count; -} - -static ssize_t fts_cover_mode_store( - struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - int ret = 0; - struct fts_ts_data *ts_data = fts_data; - - if (FTS_SYSFS_ECHO_ON(buf)) { - if (!ts_data->cover_mode) { - FTS_DEBUG("enter cover mode"); - ret = fts_ex_mode_switch(MODE_COVER, ENABLE); - if (ret >= 0) { - ts_data->cover_mode = ENABLE; - } - } - } else if (FTS_SYSFS_ECHO_OFF(buf)) { - if (ts_data->cover_mode) { - FTS_DEBUG("exit cover mode"); - ret = fts_ex_mode_switch(MODE_COVER, DISABLE); - if (ret >= 0) { - ts_data->cover_mode = DISABLE; - } - } - } - - FTS_DEBUG("cover mode:%d", ts_data->cover_mode); - return count; -} - -static ssize_t fts_charger_mode_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - int count = 0; - u8 val = 0; - struct fts_ts_data *ts_data = fts_data; - struct input_dev *input_dev = ts_data->input_dev; - - mutex_lock(&input_dev->mutex); - fts_read_reg(FTS_REG_CHARGER_MODE_EN, &val); - count = snprintf(buf + count, PAGE_SIZE, "Charger Mode:%s\n", - ts_data->charger_mode ? "On" : "Off"); - count += snprintf(buf + count, PAGE_SIZE, "Charger Reg(0x8B):%d\n", val); - mutex_unlock(&input_dev->mutex); - - return count; -} - -static ssize_t fts_charger_mode_store( - struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - int ret = 0; - struct fts_ts_data *ts_data = fts_data; - - if (FTS_SYSFS_ECHO_ON(buf)) { - if (!ts_data->charger_mode) { - FTS_DEBUG("enter charger mode"); - ret = fts_ex_mode_switch(MODE_CHARGER, ENABLE); - if (ret >= 0) { - ts_data->charger_mode = ENABLE; - } - } - } else if (FTS_SYSFS_ECHO_OFF(buf)) { - if (ts_data->charger_mode) { - FTS_DEBUG("exit charger mode"); - ret = fts_ex_mode_switch(MODE_CHARGER, DISABLE); - if (ret >= 0) { - ts_data->charger_mode = DISABLE; - } - } - } - - FTS_DEBUG("charger mode:%d", ts_data->glove_mode); - return count; -} - - -/* read and write charger mode - * read example: cat fts_glove_mode ---read glove mode - * write example:echo 1 > fts_glove_mode ---write glove mode to 01 - */ -static DEVICE_ATTR(fts_glove_mode, S_IRUGO | S_IWUSR, - fts_glove_mode_show, fts_glove_mode_store); - -static DEVICE_ATTR(fts_cover_mode, S_IRUGO | S_IWUSR, - fts_cover_mode_show, fts_cover_mode_store); - -static DEVICE_ATTR(fts_charger_mode, S_IRUGO | S_IWUSR, - fts_charger_mode_show, fts_charger_mode_store); - -static struct attribute *fts_touch_mode_attrs[] = { - &dev_attr_fts_glove_mode.attr, - &dev_attr_fts_cover_mode.attr, - &dev_attr_fts_charger_mode.attr, - NULL, -}; - -static struct attribute_group fts_touch_mode_group = { - .attrs = fts_touch_mode_attrs, -}; - -int fts_ex_mode_recovery(struct fts_ts_data *ts_data) -{ - if (ts_data->glove_mode) { - fts_ex_mode_switch(MODE_GLOVE, ENABLE); - } - - if (ts_data->cover_mode) { - fts_ex_mode_switch(MODE_COVER, ENABLE); - } - - if (ts_data->charger_mode) { - fts_ex_mode_switch(MODE_CHARGER, ENABLE); - } - - return 0; -} - -int fts_ex_mode_init(struct fts_ts_data *ts_data) -{ - int ret = 0; - - ts_data->glove_mode = DISABLE; - ts_data->cover_mode = DISABLE; - ts_data->charger_mode = DISABLE; - - ret = sysfs_create_group(&ts_data->dev->kobj, &fts_touch_mode_group); - if (ret < 0) { - FTS_ERROR("create sysfs(ex_mode) fail"); - sysfs_remove_group(&ts_data->dev->kobj, &fts_touch_mode_group); - return ret; - } else { - FTS_DEBUG("create sysfs(ex_mode) succeedfully"); - } - - return 0; -} - -int fts_ex_mode_exit(struct fts_ts_data *ts_data) -{ - sysfs_remove_group(&ts_data->dev->kobj, &fts_touch_mode_group); - return 0; -} diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_flash.c b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_flash.c deleted file mode 100755 index 2f85144cde9b..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_flash.c +++ /dev/null @@ -1,618 +0,0 @@ -/* - * - * FocalTech fts TouchScreen driver. - * - * Copyright (c) 2012-2019, Focaltech Ltd. All rights reserved. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/***************************************************************************** -* -* File Name: focaltech_flash.c -* -* Author: Focaltech Driver Team -* -* Created: 2017-12-06 -* -* Abstract: -* -* Reference: -* -*****************************************************************************/ - -/***************************************************************************** -* 1.Included header files -*****************************************************************************/ -#include "focaltech_core.h" -#include "focaltech_flash.h" - -/***************************************************************************** -* Static variables -*****************************************************************************/ -#define FTS_FW_REQUEST_SUPPORT 1 -/* Example: focaltech_ts_fw_tianma.bin */ -#define FTS_FW_NAME_PREX_WITH_REQUEST "" - -/***************************************************************************** -* Global variable or extern global variabls/functions -*****************************************************************************/ -u8 fw_file[] = { -}; - -u8 fw_file2[] = { -}; - -u8 fw_file3[] = { -}; - -struct upgrade_module module_list[] = { - {FTS_MODULE_ID, FTS_MODULE_NAME, fw_file, sizeof(fw_file)}, - {FTS_MODULE2_ID, FTS_MODULE2_NAME, fw_file2, sizeof(fw_file2)}, - {FTS_MODULE3_ID, FTS_MODULE3_NAME, fw_file3, sizeof(fw_file3)}, -}; - -struct fts_upgrade *fwupgrade; - -int fts_check_bootid(void) -{ - int ret = 0; - u8 cmd = 0; - u8 id[2] = { 0 }; - struct ft_chip_t *chip_id = &fts_data->ic_info.ids; - - cmd = FTS_CMD_READ_ID; - ret = fts_read(&cmd, 1, id, 2); - if (ret < 0) { - FTS_ERROR("read boot id fail"); - return ret; - } - - FTS_INFO("read boot id:0x%02x 0x%02x", id[0], id[1]); - if ((chip_id->chip_idh == id[0]) && (chip_id->chip_idl == id[1])) { - return 0; - } - - return -EIO; -} - -static int fts_fw_download(const u8 *buf, u32 len, bool need_reset) -{ - int ret = 0; - int i = 0; - struct fts_ts_data *ts_data = fts_data; - - FTS_INFO("fw upgrade download function"); - if (!buf || (len < FTS_MIN_LEN)) { - FTS_ERROR("fw/len(%d) is invalid", len); - return -EINVAL; - } - - ts_data->fw_loading = 1; - fts_irq_disable(); -#if FTS_ESDCHECK_EN - fts_esdcheck_switch(DISABLE); -#endif - - for (i = 0; i < 3; i++) { - FTS_INFO("fw download times:%d", i + 1); - ret = fts_fw_write_start(buf, len, need_reset); - if (0 == ret) - break; - } - if (i >= 3) { - FTS_ERROR("fw download fail"); - ret = -EIO; - goto err_fw_download; - } - -#if FTS_ESDCHECK_EN - fts_esdcheck_switch(ENABLE); -#endif - - ret = 0; -err_fw_download: - fts_irq_enable(); - ts_data->fw_loading = 0; - - return ret; - } - -static int fts_read_file(char *file_name, u8 **file_buf) -{ - int ret = 0; - char file_path[FILE_NAME_LENGTH] = { 0 }; - struct file *filp = NULL; - struct inode *inode; - mm_segment_t old_fs; - loff_t pos; - loff_t file_len = 0; - - if ((NULL == file_name) || (NULL == file_buf)) { - FTS_ERROR("filename/filebuf is NULL"); - return -EINVAL; - } - - snprintf(file_path, FILE_NAME_LENGTH, "%s%s", FTS_FW_BIN_FILEPATH, file_name); - filp = filp_open(file_path, O_RDONLY, 0); - if (IS_ERR(filp)) { - FTS_ERROR("open %s file fail", file_path); - return -ENOENT; - } - -#if 1 - inode = filp->f_inode; -#else - /* reserved for linux earlier verion */ - inode = filp->f_dentry->d_inode; -#endif - - file_len = inode->i_size; - *file_buf = (u8 *)vmalloc(file_len); - if (NULL == *file_buf) { - FTS_ERROR("file buf malloc fail"); - filp_close(filp, NULL); - return -ENOMEM; - } - old_fs = get_fs(); - set_fs(KERNEL_DS); - pos = 0; - ret = vfs_read(filp, *file_buf, file_len , &pos); - if (ret < 0) - FTS_ERROR("read file fail"); - FTS_INFO("file len:%d read len:%d pos:%d", (u32)file_len, ret, (u32)pos); - filp_close(filp, NULL); - set_fs(old_fs); - - return ret; -} - -int fts_upgrade_bin(char *fw_name, bool force) -{ - int ret = 0; - u32 fw_file_len = 0; - u8 *fw_file_buf = NULL; - struct fts_upgrade *upg = fwupgrade; - - FTS_INFO("start upgrade with fw bin"); - if (NULL == upg) { - FTS_ERROR("upgrade/func is null"); - return -EINVAL; - } - - if (upg->ts_data->fw_loading) { - FTS_INFO("fw is loading, not download again"); - return -EINVAL; - } - - ret = fts_read_file(fw_name, &fw_file_buf); - if ((ret < 0) || (ret < FTS_MIN_LEN) || (ret > FTS_MAX_LEN_FILE)) { - FTS_ERROR("read fw bin file(sdcard) fail, len:%d", fw_file_len); - goto err_bin; - } - - fw_file_len = ret; - FTS_INFO("fw bin file len:%d", fw_file_len); - ret = fts_fw_download(fw_file_buf, fw_file_len, true); - if (ret < 0) { - FTS_ERROR("upgrade fw bin failed"); - goto err_bin; - } - - FTS_INFO("upgrade fw bin success"); - -err_bin: - if (fw_file_buf) { - vfree(fw_file_buf); - fw_file_buf = NULL; - } - return ret; -} - - -int fts_enter_test_environment(bool test_state) -{ - int ret = 0; - u8 detach_flag = 0; - struct fts_upgrade *upg = fwupgrade; - - FTS_INFO("fw test download function"); - if (!upg) { - FTS_ERROR("upg is null"); - return -EINVAL; - } - - if (fts_data->fw_loading) { - FTS_INFO("fw is loading, not download again"); - return -EINVAL; - } - - if (!upg->fw || (upg->fw_length <= FTS_MAX_LEN_APP)) { - FTS_INFO("not multi-app"); - return 0; - } - - if (test_state) { - ret = fts_fw_download(upg->fw + FTS_MAX_LEN_APP, upg->fw_length, true); - } else { - ret = fts_fw_download(upg->fw, upg->fw_length, true); - } - if (ret < 0) { - FTS_ERROR("fw(app2) download fail"); - return ret; - } - - msleep(50); - ret = fts_read_reg(FTS_REG_FACTORY_MODE_DETACH_FLAG, &detach_flag); - FTS_INFO("regb4:0x%02x", detach_flag); - - return 0; -} - -static int fts_fw_resume(void) -{ - int ret = 0; - struct fts_upgrade *upg = fwupgrade; - const struct firmware *fw = NULL; - char fwname[FILE_NAME_LENGTH] = { 0 }; - - FTS_INFO("fw upgrade resume function"); - if (!upg || !upg->fw) { - FTS_ERROR("upg/fw is null"); - return -EINVAL; - } - - if (upg->ts_data->fw_loading) { - FTS_INFO("fw is loading, not download again"); - return -EINVAL; - } - - snprintf(fwname, FILE_NAME_LENGTH, "%s%s.bin", \ - FTS_FW_NAME_PREX_WITH_REQUEST, upg->module_info->vendor_name); - - /* 1. request firmware */ - ret = request_firmware(&fw, fwname, upg->ts_data->dev); - if (ret != 0) { - FTS_ERROR("%s:firmware(%s) request fail,ret=%d\n", - __func__, fwname, ret); - FTS_INFO("download fw from bootimage"); - ret = fts_fw_download(upg->fw, upg->fw_length, false); - } else { - FTS_INFO("firmware(%s) request successfully", fwname); - ret = fts_fw_download(fw->data, fw->size, false); - } - if (ret < 0) { - FTS_ERROR("fw resume download failed"); - return ret; - } - - /* update to newest fw if needed */ - if (fw != NULL) { - u8 *tmpbuf = NULL; - if (upg->fw_from_request) - vfree(upg->fw); - tmpbuf = vmalloc(fw->size); - if (NULL == tmpbuf) { - FTS_ERROR("fw buffer vmalloc fail"); - ret = -ENOMEM; - goto FTS_FW_RESUME_VMALLOC_ERROR; - } else { - memcpy(tmpbuf, fw->data, fw->size); - upg->fw = tmpbuf; - upg->fw_length = fw->size; - upg->fw_from_request = 1; - } - } - -FTS_FW_RESUME_VMALLOC_ERROR: - if (fw != NULL) { - release_firmware(fw); - fw = NULL; - } - - return ret; -} - -int fts_fw_recovery(void) -{ - int ret = 0; - u8 boot_state = 0; - u8 chip_id = 0; - struct fts_upgrade *upg = fwupgrade; - - FTS_INFO("check if boot recovery"); - if (!upg || !upg->ts_data) { - FTS_ERROR("upg/ts_data is null"); - return -EINVAL; - } - - if (upg->ts_data->fw_loading) { - FTS_INFO("fw is loading, not download again"); - return -EINVAL; - } - - upg->ts_data->fw_is_running = false; - if (!upg->ts_data->force_reflash) { - ret = fts_check_bootid(); - if (ret < 0) { - FTS_ERROR("check boot id fail"); - upg->ts_data->fw_is_running = true; - return ret; - } - - ret = fts_read_reg(0xD0, &boot_state); - if (ret < 0) { - FTS_ERROR("read boot state failed, ret=%d", ret); - upg->ts_data->fw_is_running = true; - return ret; - } - - if (boot_state != 0x01) { - FTS_INFO("not in boot mode(0x%x),exit", boot_state); - upg->ts_data->fw_is_running = true; - return -EIO; - } - - FTS_INFO("abnormal situation,need download fw"); - } - - ret = fts_fw_resume(); - if (ret < 0) { - FTS_ERROR("fts_fw_resume fail"); - return ret; - } - msleep(10); - ret = fts_read_reg(FTS_REG_CHIP_ID, &chip_id); - FTS_INFO("read chip id:0x%02x", chip_id); - - fts_tp_state_recovery(upg->ts_data); - - FTS_INFO("boot recovery pass"); - return ret; -} - -int fts_fw_update_vendor_name(const char* name) { - struct fts_upgrade *upg = fwupgrade; - char* pos; - int len; - - if (!upg || !upg->module_info) { - FTS_ERROR("upgrade struct not init"); - return -EINVAL; - } - - len = strlen(name); - if (len > FILE_NAME_LENGTH) { - FTS_ERROR("vendor name is too long"); - return -EINVAL; - } - pos = strstr(name, ".bin"); - if (pos == NULL) - snprintf(upg->module_info->vendor_name, FILE_NAME_LENGTH, "%s", name); - else { - len = len - strlen(".bin"); - snprintf(upg->module_info->vendor_name, len + 1, "%s", name); - } - return 0; -} - -static int fts_fwupg_get_module_info(struct fts_upgrade *upg) -{ - int i = 0; - struct upgrade_module *info = &module_list[0]; - - if (!upg || !upg->ts_data) { - FTS_ERROR("upg/ts_data is null"); - return -EINVAL; - } - - if (FTS_GET_MODULE_NUM > 1) { - FTS_INFO("module id:%04x", upg->module_id); - for (i = 0; i < FTS_GET_MODULE_NUM; i++) { - info = &module_list[i]; - if (upg->module_id == info->id) { - FTS_INFO("module id match, get fw file successfully"); - break; - } - } - if (i >= FTS_GET_MODULE_NUM) { - FTS_ERROR("no module id match, don't get file"); - return -ENODATA; - } - } - - upg->module_info = info; - return 0; -} - -static int fts_get_fw_file_via_request_firmware(struct fts_upgrade *upg) -{ - int ret = 0; - const struct firmware *fw = NULL; - u8 *tmpbuf = NULL; - char fwname[FILE_NAME_LENGTH] = { 0 }; - - snprintf(fwname, FILE_NAME_LENGTH, "%s%s.bin", \ - FTS_FW_NAME_PREX_WITH_REQUEST, \ - upg->module_info->vendor_name); - - ret = request_firmware(&fw, fwname, upg->ts_data->dev); - if (0 == ret) { - FTS_INFO("firmware(%s) request successfully", fwname); - tmpbuf = vmalloc(fw->size); - if (NULL == tmpbuf) { - FTS_ERROR("fw buffer vmalloc fail"); - ret = -ENOMEM; - } else { - memcpy(tmpbuf, fw->data, fw->size); - upg->fw = tmpbuf; - upg->fw_length = fw->size; - upg->fw_from_request = 1; - } - } else { - FTS_INFO("firmware(%s) request fail,ret=%d", fwname, ret); - } - - if (fw != NULL) { - release_firmware(fw); - fw = NULL; - } - - return ret; -} - -static int fts_get_fw_file_via_i(struct fts_upgrade *upg) -{ - upg->fw = upg->module_info->fw_file; - upg->fw_length = upg->module_info->fw_len; - upg->fw_from_request = 0; - - return 0; -} - -/***************************************************************************** - * Name: fts_fwupg_get_fw_file - * Brief: get fw image/file, - * If support muitl modules, please set FTS_GET_MODULE_NUM, and FTS_- - * MODULE_ID/FTS_MODULE_NAME; - * If get fw via .i file, please set FTS_FW_REQUEST_SUPPORT=0, and F- - * TS_MODULE_ID; will use module id to distingwish different modules; - * If get fw via reques_firmware(), please set FTS_FW_REQUEST_SUPPORT - * =1, and FTS_MODULE_NAME; fw file name will be composed of "focalt- - * ech_ts_fw_" & FTS_VENDOR_NAME; - * - * If have flash, module_id=vendor_id, If non-flash,module_id need - * transfer from LCD driver(gpio or lcm_id or ...); - * Input: - * Output: - * Return: return 0 if success, otherwise return error code - *****************************************************************************/ -static int fts_fwupg_get_fw_file(struct fts_upgrade *upg) -{ - int ret = 0; - bool get_fw_i_flag = false; - - FTS_DEBUG("get upgrade fw file"); - if (!upg || !upg->ts_data) { - FTS_ERROR("upg/ts_data is null"); - return -EINVAL; - } - - ret = fts_fwupg_get_module_info(upg); - if ((ret < 0) || (!upg->module_info)) { - FTS_ERROR("get module info fail"); - return ret; - } - - if (FTS_FW_REQUEST_SUPPORT) { - msleep(500); - ret = fts_get_fw_file_via_request_firmware(upg); - if (ret != 0) { - get_fw_i_flag = true; - } - } else { - get_fw_i_flag = true; - } - - if (get_fw_i_flag) { - ret = fts_get_fw_file_via_i(upg); - } - - FTS_INFO("upgrade fw file len:%d", upg->fw_length); - if ((upg->fw_length < FTS_MIN_LEN) - || (upg->fw_length > FTS_MAX_LEN_FILE)) { - FTS_ERROR("fw file len(%d) fail", upg->fw_length); - return -ENODATA; - } - - return ret; -} - -static void fts_fwupg_work(struct work_struct *work) -{ - int ret = 0; - u8 chip_id = 0; - struct fts_upgrade *upg = fwupgrade; - - FTS_INFO("fw upgrade work function"); - if (!upg || !upg->ts_data) { - FTS_ERROR("upg/ts_data is null"); - return ; - } - - /* get fw */ - ret = fts_fwupg_get_fw_file(upg); - if (ret < 0) { - FTS_ERROR("get file fail, can't upgrade"); - return ; - } - -#if !FTS_AUTO_UPGRADE_EN - FTS_INFO("FTS_AUTO_UPGRADE_EN is disabled, not upgrade when power on"); - return ; -#endif - - if (upg->ts_data->fw_loading) { - FTS_INFO("fw is loading, not download again"); - return ; - } - - ret = fts_fw_download(upg->fw, upg->fw_length, true); - if (ret < 0) { - FTS_ERROR("fw auto download failed"); - } else { - msleep(50); - ret = fts_read_reg(FTS_REG_CHIP_ID, &chip_id); - FTS_INFO("read chip id:0x%02x", chip_id); - } -} - -int fts_fwupg_init(struct fts_ts_data *ts_data) -{ - FTS_INFO("fw upgrade init function"); - - if (!ts_data || !ts_data->ts_workqueue) { - FTS_ERROR("ts_data/workqueue is NULL, can't run upgrade function"); - return -EINVAL; - } - - fwupgrade = (struct fts_upgrade *)kzalloc(sizeof(*fwupgrade), GFP_KERNEL); - if (NULL == fwupgrade) { - FTS_ERROR("malloc memory for upgrade fail"); - return -ENOMEM; - } - -#if FTS_ESDCHECK_EN - fts_esdcheck_switch(DISABLE); -#endif - - fwupgrade->ts_data = ts_data; - INIT_WORK(&ts_data->fwupg_work, fts_fwupg_work); - queue_work(ts_data->ts_workqueue, &ts_data->fwupg_work); - - return 0; -} - -int fts_fwupg_exit(struct fts_ts_data *ts_data) -{ - FTS_FUNC_ENTER(); - if (fwupgrade) { - if (fwupgrade->fw_from_request) { - vfree(fwupgrade->fw); - fwupgrade->fw = NULL; - } - - kfree(fwupgrade); - fwupgrade = NULL; - } - FTS_FUNC_EXIT(); - return 0; -} diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_flash.h b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_flash.h deleted file mode 100755 index f15c1ee93690..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_flash.h +++ /dev/null @@ -1,185 +0,0 @@ -/************************************************************************ -* Copyright (C) 2012-2019, Focaltech Systems (R)£¬All Rights Reserved. -* -* File Name: focaltech_flash.h -* -* Author: Focaltech Driver Team -* -* Created: 2016-08-07 -* -* Abstract: -* -************************************************************************/ -#ifndef __LINUX_FOCALTECH_FLASH_H__ -#define __LINUX_FOCALTECH_FLASH_H__ - -/***************************************************************************** -* 1.Included header files -*****************************************************************************/ -#include "focaltech_core.h" - -/***************************************************************************** -* Private constant and macro definitions using #define -*****************************************************************************/ -#define FTS_CMD_RESET 0x07 -#define FTS_ROMBOOT_CMD_SET_PRAM_ADDR 0xAD -#define FTS_ROMBOOT_CMD_SET_PRAM_ADDR_LEN 4 -#define FTS_ROMBOOT_CMD_WRITE 0xAE -#define FTS_ROMBOOT_CMD_START_APP 0x08 -#define FTS_DELAY_PRAMBOOT_START 10 -#define FTS_ROMBOOT_CMD_ECC 0xCC -#define FTS_PRAM_SADDR 0x000000 -#define FTS_DRAM_SADDR 0xD00000 - -#define FTS_CMD_READ 0x03 -#define FTS_CMD_READ_DELAY 1 -#define FTS_CMD_READ_LEN 4 -#define FTS_CMD_FLASH_TYPE 0x05 -#define FTS_CMD_FLASH_MODE 0x09 -#define FLASH_MODE_WRITE_FLASH_VALUE 0x0A -#define FLASH_MODE_UPGRADE_VALUE 0x0B -#define FLASH_MODE_LIC_VALUE 0x0C -#define FLASH_MODE_PARAM_VALUE 0x0D -#define FTS_CMD_ERASE_APP 0x61 -#define FTS_REASE_APP_DELAY 1350 -#define FTS_ERASE_SECTOR_DELAY 60 -#define FTS_RETRIES_REASE 50 -#define FTS_RETRIES_DELAY_REASE 200 -#define FTS_CMD_FLASH_STATUS 0x6A -#define FTS_CMD_FLASH_STATUS_LEN 2 -#define FTS_CMD_FLASH_STATUS_NOP 0x0000 -#define FTS_CMD_FLASH_STATUS_ECC_OK 0xF055 -#define FTS_CMD_FLASH_STATUS_ERASE_OK 0xF0AA -#define FTS_CMD_FLASH_STATUS_WRITE_OK 0x1000 -#define FTS_CMD_ECC_INIT 0x64 -#define FTS_CMD_ECC_CAL 0x65 -#define FTS_CMD_ECC_CAL_LEN 6 -#define FTS_RETRIES_ECC_CAL 10 -#define FTS_RETRIES_DELAY_ECC_CAL 50 -#define FTS_CMD_ECC_READ 0x66 -#define FTS_CMD_DATA_LEN 0xB0 -#define FTS_CMD_APP_DATA_LEN_INCELL 0x7A -#define FTS_CMD_DATA_LEN_LEN 4 -#define FTS_CMD_WRITE 0xBF -#define FTS_RETRIES_WRITE 100 -#define FTS_RETRIES_DELAY_WRITE 1 -#define FTS_CMD_WRITE_LEN 6 -#define FTS_DELAY_READ_ID 20 -#define FTS_DELAY_UPGRADE_RESET 80 -#define PRAMBOOT_MIN_SIZE 0x120 -#define PRAMBOOT_MAX_SIZE (64*1024) -#define FTS_FLASH_PACKET_LENGTH 32 /* max=128 */ -#define FTS_MAX_LEN_ECC_CALC 0xFFFE /* must be even */ -#define FTS_MIN_LEN 0x120 -#define FTS_MAX_LEN_FILE (128 * 1024) -#define FTS_MAX_LEN_APP (64 * 1024) -#define FTS_MAX_LEN_APP_PARAMS (32 * 1024) -#define FTS_MAX_LEN_SECTOR (4 * 1024) -#define FTS_CONIFG_VENDORID_OFF 0x04 -#define FTS_CONIFG_MODULEID_OFF 0x1E -#define FTS_CONIFG_PROJECTID_OFF 0x20 -#define FTS_APPINFO_OFF 0x100 -#define FTS_APPINFO_APPLEN_OFF 0x00 -#define FTS_APPINFO_APPLEN2_OFF 0x12 -#define FTS_REG_UPGRADE 0xFC -#define FTS_REG_UPGRADE2 0xBC -#define FTS_UPGRADE_AA 0xAA -#define FTS_UPGRADE_55 0x55 -#define FTS_DELAY_UPGRADE_AA 10 -#define FTS_UPGRADE_LOOP 30 -#define FTS_HEADER_LEN 32 -#define FTS_FW_BIN_FILEPATH "/sdcard/" -#define FTS_FW_IDE_SIG "IDE_" -#define FTS_FW_IDE_SIG_LEN 4 -#define MAX_MODULE_VENDOR_NAME_LEN 16 - -#define FTS_ROMBOOT_CMD_ECC_NEW_LEN 7 -#define FTS_ECC_FINISH_TIMEOUT 100 -#define FTS_ROMBOOT_CMD_ECC_FINISH 0xCE -#define FTS_ROMBOOT_CMD_ECC_FINISH_OK_A5 0xA5 -#define FTS_ROMBOOT_CMD_ECC_FINISH_OK_00 0x00 -#define FTS_ROMBOOT_CMD_ECC_READ 0xCD -#define AL2_FCS_COEF ((1 << 15) + (1 << 10) + (1 << 3)) - -#define FTS_APP_INFO_OFFSET 0x100 - -enum FW_STATUS { - FTS_RUN_IN_ERROR, - FTS_RUN_IN_APP, - FTS_RUN_IN_ROM, - FTS_RUN_IN_PRAM, - FTS_RUN_IN_BOOTLOADER, -}; - -enum FW_FLASH_MODE { - FLASH_MODE_APP, - FLASH_MODE_LIC, - FLASH_MODE_PARAM, - FLASH_MODE_ALL, -}; - -enum ECC_CHECK_MODE { - ECC_CHECK_MODE_XOR, - ECC_CHECK_MODE_CRC16, -}; - -/***************************************************************************** -* Private enumerations, structures and unions using typedef -*****************************************************************************/ -/* IC info */ -struct upgrade_func { - u64 ctype[FTX_MAX_COMPATIBLE_TYPE]; - u32 fwveroff; - u32 fwcfgoff; - u32 appoff; - u32 licoff; - u32 paramcfgoff; - u32 paramcfgveroff; - u32 paramcfg2off; - int pram_ecc_check_mode; - int fw_ecc_check_mode; - bool new_return_value_from_ic; - bool appoff_handle_in_ic; - bool is_reset_register_BC; - bool read_boot_id_need_reset; - bool hid_supported; - bool pramboot_supported; - u8 *pramboot; - u32 pb_length; - int (*init)(u8 *, u32); - int (*upgrade)(u8 *, u32); - int (*get_hlic_ver)(u8 *); - int (*lic_upgrade)(u8 *, u32); - int (*param_upgrade)(u8 *, u32); - int (*force_upgrade)(u8 *, u32); -}; - -struct upgrade_module { - int id; - char vendor_name[MAX_MODULE_VENDOR_NAME_LEN]; - u8 *fw_file; - u32 fw_len; -}; - -struct fts_upgrade { - struct fts_ts_data *ts_data; - struct upgrade_module *module_info; - struct upgrade_func *func; - int module_id; - bool fw_from_request; - u8 *fw; - u32 fw_length; - u8 *lic; - u32 lic_length; -}; - -/***************************************************************************** -* Global variable or extern global variabls/functions -*****************************************************************************/ -int fts_check_bootid(void); -int fts_fw_write_start(const u8 *buf, u32 len, bool need_reset); - -/***************************************************************************** -* Static function prototypes -*****************************************************************************/ -#endif diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_flash_ft8719.c b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_flash_ft8719.c deleted file mode 100755 index 5048ff1a984f..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_flash_ft8719.c +++ /dev/null @@ -1,364 +0,0 @@ -/* - * - * FocalTech fts TouchScreen driver. - * - * Copyright (c) 2012-2019, Focaltech Ltd. All rights reserved. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/***************************************************************************** -* -* File Name: focaltech_flash.c -* -* Author: Focaltech Driver Team -* -* Created: 2017-12-06 -* -* Abstract: -* -* Reference: -* -*****************************************************************************/ - -/***************************************************************************** -* 1.Included header files -*****************************************************************************/ -#include "focaltech_core.h" -#include "focaltech_flash.h" - -/***************************************************************************** -* Static variables -*****************************************************************************/ -#define FTS_READ_BOOT_ID_TIMEOUT 3 -#define FTS_FLASH_PACKET_LENGTH_SPI_LOW (4 * 1024 - 4) -#define FTS_FLASH_PACKET_LENGTH_SPI (64 * 1024) - -/***************************************************************************** -* Global variable or extern global variabls/functions -*****************************************************************************/ -static int fts_fwupg_hardware_reset_to_boot(void) -{ - fts_reset_proc(0); - mdelay(8); - - return 0; -} - -static int fts_enter_into_boot(void) -{ - int ret = 0; - int i = 0; - int j = 0; - u8 cmd = 0; - - FTS_INFO("enter into boot environment"); - for (i = 0; i < FTS_UPGRADE_LOOP; i++) { - /* hardware tp reset to boot */ - fts_fwupg_hardware_reset_to_boot(); - - /* enter into boot & check boot id*/ - for (j = 0; j < FTS_READ_BOOT_ID_TIMEOUT; j++) { - cmd = FTS_CMD_START1; - ret = fts_write(&cmd, 1); - if (ret >= 0) { - mdelay(8); - ret = fts_check_bootid(); - if (0 == ret) { - FTS_INFO("boot id check pass, retry=%d", i); - return 0; - } - } - } - } - - return -EIO; -} - -static bool fts_check_fast_download(void) -{ - int ret = 0; - u8 cmd[6] = {0xF2, 0x00, 0x78, 0x0A, 0x00, 0x02}; - u8 value = 0; - u8 value2[2] = { 0 }; - - ret = fts_read_reg(0xdb, &value); - if (ret < 0) { - FTS_ERROR("read 0xdb fail"); - goto read_err; - } - - ret = fts_read(cmd, 6, value2, 2); - if (ret < 0) { - FTS_ERROR("read f2 fail"); - goto read_err; - } - - FTS_INFO("0xdb = 0x%x, 0xF2 = 0x%x", value, value2[0]); - if ((value >= 0x18) && (value2[0] == 0x55)) { - FTS_INFO("IC support fast-download"); - return true; - } - -read_err: - FTS_INFO("IC not support fast-download"); - return false; -} - -static int fts_pram_write(u32 saddr, const u8 *buf, u32 len) -{ - int ret = 0; - int i = 0; - int j = 0; - u8 *cmd; - u32 addr = 0; - u32 offset = 0; - u32 remainder = 0; - u32 packet_number; - u32 packet_len = 0; - u32 packet_size = FTS_FLASH_PACKET_LENGTH_SPI; - bool fd_support = true; - - FTS_INFO("pram write"); - if (NULL == buf) { - FTS_ERROR("fw buf is null"); - return -EINVAL; - } - - if ((len < FTS_MIN_LEN) || (len > FTS_MAX_LEN_APP)) { - FTS_ERROR("fw length(%d) fail", len); - return -EINVAL; - } - - fd_support = fts_check_fast_download(); - if (!fd_support) - packet_size = FTS_FLASH_PACKET_LENGTH_SPI_LOW; - cmd = kzalloc(packet_size + FTS_CMD_WRITE_LEN, GFP_KERNEL); - if (NULL == cmd) { - FTS_ERROR("malloc memory for pram write buffer fail"); - return -ENOMEM; - } - - packet_number = len / packet_size; - remainder = len % packet_size; - if (remainder > 0) - packet_number++; - packet_len = packet_size; - - cmd[0] = FTS_ROMBOOT_CMD_WRITE; - for (i = 0; i < packet_number; i++) { - offset = i * packet_size; - addr = saddr + offset; - cmd[1] = BYTE_OFF_16(addr); - cmd[2] = BYTE_OFF_8(addr); - cmd[3] = BYTE_OFF_0(addr); - - /* last packet */ - if ((i == (packet_number - 1)) && remainder) - packet_len = remainder; - cmd[4] = BYTE_OFF_8(packet_len); - cmd[5] = BYTE_OFF_0(packet_len); - - for (j = 0; j < packet_len; j++) { - cmd[FTS_CMD_WRITE_LEN + j] = buf[offset + j]; - } - ret = fts_write(&cmd[0], FTS_CMD_WRITE_LEN + packet_len); - if (ret < 0) { - FTS_ERROR("write fw to pram(%d) fail", i); - goto write_pram_err; - } - - if (!fd_support) - mdelay(3); - } - -write_pram_err: - if (cmd) { - kfree(cmd); - cmd = NULL; - } - return ret; -} - -static int fts_ecc_cal_tp(u32 ecc_saddr, u32 ecc_len, u16 *ecc_value) -{ - int ret = 0; - int i = 0; - u8 cmd[FTS_ROMBOOT_CMD_ECC_NEW_LEN] = { 0 }; - u8 value[2] = { 0 }; - - FTS_INFO("ecc calc in tp"); - cmd[0] = FTS_ROMBOOT_CMD_ECC; - cmd[1] = BYTE_OFF_16(ecc_saddr); - cmd[2] = BYTE_OFF_8(ecc_saddr); - cmd[3] = BYTE_OFF_0(ecc_saddr); - cmd[4] = BYTE_OFF_16(ecc_len); - cmd[5] = BYTE_OFF_8(ecc_len); - cmd[6] = BYTE_OFF_0(ecc_len); - - /* make boot to calculate ecc in pram */ - ret = fts_write(cmd, FTS_ROMBOOT_CMD_ECC_NEW_LEN); - if (ret < 0) { - FTS_ERROR("ecc calc cmd fail"); - return ret; - } - mdelay(3); - - /* wait boot calculate ecc finish */ - cmd[0] = FTS_ROMBOOT_CMD_ECC_FINISH; - for (i = 0; i < FTS_ECC_FINISH_TIMEOUT; i++) { - ret = fts_read(cmd, 1, value, 1); - if (ret < 0) { - FTS_ERROR("ecc finish cmd fail"); - return ret; - } - if (0 == value[0]) - break; - mdelay(1); - } - if (i >= FTS_ECC_FINISH_TIMEOUT) { - FTS_ERROR("wait ecc finish timeout"); - return -EIO; - } - - /* get ecc value calculate in boot */ - cmd[0] = FTS_ROMBOOT_CMD_ECC_READ; - ret = fts_read(cmd, 1, value, 2); - if (ret < 0) { - FTS_ERROR("ecc read cmd fail"); - return ret; - } - - *ecc_value = ((u16)(value[0] << 8) + value[1]) & 0x0000FFFF; - return 0; -} - -static int fts_ecc_cal_host(const u8 *data, u32 data_len, u16 *ecc_value) -{ - u16 ecc = 0; - u16 i = 0; - u16 j = 0; - u16 al2_fcs_coef = AL2_FCS_COEF; - - for (i = 0; i < data_len; i += 2 ) { - ecc ^= ((data[i] << 8) | (data[i + 1])); - for (j = 0; j < 16; j ++) { - if (ecc & 0x01) - ecc = (u16)((ecc >> 1) ^ al2_fcs_coef); - else - ecc >>= 1; - } - } - - *ecc_value = ecc & 0x0000FFFF; - return 0; -} - -static int fts_pram_start(void) -{ - int ret = 0; - u8 cmd = FTS_ROMBOOT_CMD_START_APP; - - FTS_INFO("remap to start pram"); - ret = fts_write(&cmd, 1); - if (ret < 0) { - FTS_ERROR("write start pram cmd fail"); - return ret; - } - - return 0; -} - -/* - * description: download fw to IC and run - * - * param - buf: const, fw data buffer - * len: length of fw - * - * return 0 if success, otherwise return error code - */ -int fts_fw_write_start(const u8 *buf, u32 len, bool need_reset) -{ - int ret = 0; - u16 ecc_in_host = 0; - u16 ecc_in_tp = 0; - u32 fw_start_addr = 0; - u32 fw_len = 0; - u16 code_len = 0; - u16 code_len_n = 0; - - FTS_INFO("begin to write and start fw(bin len:%d)", len); - /* get app length */ - code_len = ((u16)buf[FTS_APP_INFO_OFFSET + 0] << 8) - + buf[FTS_APP_INFO_OFFSET + 1]; - code_len_n = ((u16)buf[FTS_APP_INFO_OFFSET + 2] << 8) - + buf[FTS_APP_INFO_OFFSET + 3]; - if ((code_len + code_len_n) != 0xFFFF) { - FTS_ERROR("code len(%x %x) fail", code_len, code_len_n); - return -EINVAL; - } - - fw_len = (u32)code_len; - if ((fw_len < FTS_MIN_LEN) || (fw_len > FTS_MAX_LEN_APP)) { - FTS_ERROR("fw length(%d) is invalid", fw_len); - return -EINVAL; - } - - FTS_INFO("fw length in fact:%d", fw_len); - fts_data->fw_is_running = false; - - if (need_reset) { - /* enter into boot environment */ - ret = fts_enter_into_boot(); - if (ret < 0) { - FTS_ERROR("enter into boot environment fail"); - return ret; - } - } - - /* write pram */ - ret = fts_pram_write(fw_start_addr, buf, fw_len); - if (ret < 0) { - FTS_ERROR("write pram fail"); - return ret; - } - - /* ecc check */ - ret = fts_ecc_cal_host(buf, fw_len, &ecc_in_host); - if (ret < 0) { - FTS_ERROR("ecc in host calc fail"); - return ret; - } - - ret = fts_ecc_cal_tp(fw_start_addr, fw_len, &ecc_in_tp); - if (ret < 0) { - FTS_ERROR("ecc in tp calc fail"); - return ret; - } - - FTS_INFO("ecc in tp:%04x host:%04x", ecc_in_tp, ecc_in_host); - if (ecc_in_tp != ecc_in_host) { - FTS_ERROR("ecc check fail"); - return -EIO; - } - - /* remap pram and run fw */ - ret = fts_pram_start(); - if (ret < 0) { - FTS_ERROR("pram start fail"); - return ret; - } - - fts_data->fw_is_running = true; - FTS_INFO("fw download successfully"); - return 0; -} - diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_flash_ft8756.c b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_flash_ft8756.c deleted file mode 100644 index 3f4b7f182d82..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_flash_ft8756.c +++ /dev/null @@ -1,448 +0,0 @@ -/* - * - * FocalTech fts TouchScreen driver. - * - * Copyright (c) 2012-2019, Focaltech Ltd. All rights reserved. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/***************************************************************************** -* -* File Name: focaltech_flash.c -* -* Author: Focaltech Driver Team -* -* Created: 2017-12-06 -* -* Abstract: -* -* Reference: -* -*****************************************************************************/ - -/***************************************************************************** -* 1.Included header files -*****************************************************************************/ -#include "focaltech_core.h" -#include "focaltech_flash.h" - -/***************************************************************************** -* Static variables -*****************************************************************************/ -#define FTS_READ_BOOT_ID_TIMEOUT 3 -#define FTS_FLASH_PACKET_LENGTH_SPI (32 * 1024 - 16) - -#define FTS_CMD_ECC_LENGTH_MAX 32766 -#define FTS_ROMBOOT_CMD_ECC_FINISH_OK 0xA5 - - -/***************************************************************************** -* Global variable or extern global variabls/functions -*****************************************************************************/ -static int fts_fwupg_hardware_reset_to_boot(void) -{ - fts_reset_proc(0); - mdelay(8); - - return 0; -} - -static int fts_enter_into_boot(void) -{ - int ret = 0; - int i = 0; - int j = 0; - u8 cmd[2] = { 0 }; - - FTS_INFO("enter into boot environment"); - for (i = 0; i < FTS_UPGRADE_LOOP; i++) { - /* hardware tp reset to boot */ - fts_fwupg_hardware_reset_to_boot(); - - /* enter into boot & check boot id*/ - for (j = 0; j < FTS_READ_BOOT_ID_TIMEOUT; j++) { - cmd[0] = FTS_CMD_START1; - ret = fts_write(cmd, 1); - if (ret >= 0) { - mdelay(8); - ret = fts_check_bootid(); - if (0 == ret) { - FTS_INFO("boot id check pass, retry=%d", i); - return 0; - } - } - } - } - - return -EIO; -} - - -static int fts_dpram_write(u32 saddr, const u8 *buf, u32 len, bool wpram) -{ - int ret = 0; - int i = 0; - int j = 0; - u8 *cmd = NULL; - u32 addr = 0; - u32 baseaddr = wpram ? FTS_PRAM_SADDR : FTS_DRAM_SADDR; - u32 offset = 0; - u32 remainder = 0; - u32 packet_number = 0; - u32 packet_len = 0; - u32 packet_size = FTS_FLASH_PACKET_LENGTH_SPI; - - FTS_INFO("dpram write"); - if (NULL == buf) { - FTS_ERROR("fw buf is null"); - return -EINVAL; - } - - if ((len < FTS_MIN_LEN) || (len > FTS_MAX_LEN_APP)) { - FTS_ERROR("fw length(%d) fail", len); - return -EINVAL; - } - - cmd = vmalloc(packet_size + FTS_CMD_WRITE_LEN); - if (NULL == cmd) { - FTS_ERROR("malloc memory for pram write buffer fail"); - return -ENOMEM; - } - memset(cmd, 0, packet_size + FTS_CMD_WRITE_LEN); - - packet_number = len / packet_size; - remainder = len % packet_size; - if (remainder > 0) - packet_number++; - packet_len = packet_size; - FTS_INFO("write data, num:%d remainder:%d", packet_number, remainder); - - for (i = 0; i < packet_number; i++) { - offset = i * packet_size; - addr = saddr + offset + baseaddr; - /* last packet */ - if ((i == (packet_number - 1)) && remainder) - packet_len = remainder; - - /* set pram address */ - cmd[0] = FTS_ROMBOOT_CMD_SET_PRAM_ADDR; - cmd[1] = BYTE_OFF_16(addr); - cmd[2] = BYTE_OFF_8(addr); - cmd[3] = BYTE_OFF_0(addr); - ret = fts_write(&cmd[0], FTS_ROMBOOT_CMD_SET_PRAM_ADDR_LEN); - if (ret < 0) { - FTS_ERROR("set pram(%d) addr(%d) fail", i, addr); - goto write_pram_err; - } - - /* write pram data */ - cmd[0] = FTS_ROMBOOT_CMD_WRITE; - for (j = 0; j < packet_len; j++) { - cmd[1 + j] = buf[offset + j]; - } - ret = fts_write(&cmd[0], 1 + packet_len); - if (ret < 0) { - FTS_ERROR("write fw to pram(%d) fail", i); - goto write_pram_err; - } - } - -write_pram_err: - if (cmd) { - vfree(cmd); - cmd = NULL; - } - return ret; -} - -static int fts_ecc_cal_tp(u32 ecc_saddr, u32 ecc_len, u16 *ecc_value) -{ - int ret = 0; - int i = 0; - u8 cmd[FTS_ROMBOOT_CMD_ECC_NEW_LEN] = { 0 }; - u8 value[2] = { 0 }; - - FTS_INFO("ecc calc in tp"); - cmd[0] = FTS_ROMBOOT_CMD_ECC; - cmd[1] = BYTE_OFF_16(ecc_saddr); - cmd[2] = BYTE_OFF_8(ecc_saddr); - cmd[3] = BYTE_OFF_0(ecc_saddr); - cmd[4] = BYTE_OFF_16(ecc_len); - cmd[5] = BYTE_OFF_8(ecc_len); - cmd[6] = BYTE_OFF_0(ecc_len); - - /* make boot to calculate ecc in pram */ - ret = fts_write(cmd, FTS_ROMBOOT_CMD_ECC_NEW_LEN); - if (ret < 0) { - FTS_ERROR("ecc calc cmd fail"); - return ret; - } - mdelay(2); - - /* wait boot calculate ecc finish */ - cmd[0] = FTS_ROMBOOT_CMD_ECC_FINISH; - for (i = 0; i < FTS_ECC_FINISH_TIMEOUT; i++) { - ret = fts_read(cmd, 1, value, 1); - if (ret < 0) { - FTS_ERROR("ecc finish cmd fail"); - return ret; - } - if (FTS_ROMBOOT_CMD_ECC_FINISH_OK == value[0]) - break; - mdelay(1); - } - if (i >= FTS_ECC_FINISH_TIMEOUT) { - FTS_ERROR("wait ecc finish timeout,ecc_finish=%x", value[0]); - return -EIO; - } - - /* get ecc value calculate in boot */ - cmd[0] = FTS_ROMBOOT_CMD_ECC_READ; - ret = fts_read(cmd, 1, value, 2); - if (ret < 0) { - FTS_ERROR("ecc read cmd fail"); - return ret; - } - - *ecc_value = ((u16)(value[0] << 8) + value[1]) & 0x0000FFFF; - return 0; -} - -static int fts_ecc_cal_host(const u8 *data, u32 data_len, u16 *ecc_value) -{ - u16 ecc = 0; - u16 i = 0; - u16 j = 0; - u16 al2_fcs_coef = AL2_FCS_COEF; - - for (i = 0; i < data_len; i += 2 ) { - ecc ^= ((data[i] << 8) | (data[i + 1])); - for (j = 0; j < 16; j ++) { - if (ecc & 0x01) - ecc = (u16)((ecc >> 1) ^ al2_fcs_coef); - else - ecc >>= 1; - } - } - - *ecc_value = ecc & 0x0000FFFF; - return 0; -} - -static int fts_ecc_check(const u8 *buf, u32 len, u32 ecc_saddr) -{ - int ret = 0; - int i = 0; - u16 ecc_in_host = 0; - u16 ecc_in_tp = 0; - int packet_length = 0; - int packet_number = 0; - int packet_remainder = 0; - int offset = 0; - u32 packet_size = FTS_CMD_ECC_LENGTH_MAX; - - packet_number = len / packet_size; - packet_remainder = len % packet_size; - if (packet_remainder) - packet_number++; - packet_length = packet_size; - - for (i = 0; i < packet_number; i++) { - /* last packet */ - if ((i == (packet_number - 1)) && packet_remainder) - packet_length = packet_remainder; - - ret = fts_ecc_cal_host(buf + offset, packet_length, &ecc_in_host); - if (ret < 0) { - FTS_ERROR("ecc in host calc fail"); - return ret; - } - - ret = fts_ecc_cal_tp(ecc_saddr + offset, packet_length, &ecc_in_tp); - if (ret < 0) { - FTS_ERROR("ecc in tp calc fail"); - return ret; - } - - FTS_DEBUG("ecc in tp:%04x,host:%04x,i:%d", ecc_in_tp, ecc_in_host, i); - if (ecc_in_tp != ecc_in_host) { - FTS_ERROR("ecc_in_tp(%x) != ecc_in_host(%x), ecc check fail", - ecc_in_tp, ecc_in_host); - return -EIO; - } - - offset += packet_length; - } - - return 0; -} - -static int fts_pram_write_ecc(const u8 *buf, u32 len) -{ - int ret = 0; - u32 pram_app_size = 0; - u16 code_len = 0; - u16 code_len_n = 0; - u32 pram_start_addr = 0; - - FTS_INFO("begin to write pram app(bin len:%d)", len); - /* get pram app length */ - code_len = ((u16)buf[FTS_APP_INFO_OFFSET + 0] << 8) - + buf[FTS_APP_INFO_OFFSET + 1]; - code_len_n = ((u16)buf[FTS_APP_INFO_OFFSET + 2] << 8) - + buf[FTS_APP_INFO_OFFSET + 3]; - if ((code_len + code_len_n) != 0xFFFF) { - FTS_ERROR("pram code len(%x %x) fail", code_len, code_len_n); - return -EINVAL; - } - - pram_app_size = (u32)code_len; - pram_app_size = pram_app_size * 2; - if ((pram_app_size < FTS_MIN_LEN) || (pram_app_size > FTS_MAX_LEN_APP)) { - FTS_ERROR("pram app length(%d) is invalid", pram_app_size); - return -EINVAL; - } - - FTS_INFO("pram app length in fact:%d", pram_app_size); - /* write pram */ - ret = fts_dpram_write(pram_start_addr, buf, pram_app_size, true); - if (ret < 0) { - FTS_ERROR("write pram fail"); - return ret; - } - - /* check ecc */ - ret = fts_ecc_check(buf, pram_app_size, pram_start_addr); - if (ret < 0) { - FTS_ERROR("pram ecc check fail"); - return ret; - } - - FTS_INFO("pram app write successfully"); - return 0; -} - -static int fts_dram_write_ecc(const u8 *buf, u32 len) -{ - int ret = 0; - u32 dram_size = 0; - u32 pram_app_size = 0; - u32 dram_start_addr = 0; - u16 const_len = 0; - u16 const_len_n = 0; - const u8 *dram_buf = NULL; - - FTS_INFO("begin to write dram data(bin len:%d)", len); - /* get dram data length */ - const_len = ((u16)buf[FTS_APP_INFO_OFFSET + 0x8] << 8) - + buf[FTS_APP_INFO_OFFSET + 0x9]; - const_len_n = ((u16)buf[FTS_APP_INFO_OFFSET + 0x0A] << 8) - + buf[FTS_APP_INFO_OFFSET + 0x0B]; - if (((const_len + const_len_n) != 0xFFFF) || (const_len == 0)) { - FTS_INFO("no support dram,const len(%x %x)", const_len, const_len_n); - return 0; - } - - dram_size = ((u32)const_len) * 2; - if ((dram_size <= 0) || (dram_size > FTS_MAX_LEN_APP_PARAMS)) { - FTS_ERROR("dram data length(%d) is invalid", dram_size); - return -EINVAL; - } - - pram_app_size = ((u32)(((u16)buf[FTS_APP_INFO_OFFSET + 0] << 8) - + buf[FTS_APP_INFO_OFFSET + 1])) * 2; - - dram_buf = buf + pram_app_size; - FTS_INFO("dram buf length in fact:%d,offset:%d", dram_size, pram_app_size); - /* write pram */ - ret = fts_dpram_write(dram_start_addr, dram_buf, dram_size, false); - if (ret < 0) { - FTS_ERROR("write dram fail"); - return ret; - } - - /* check ecc */ - ret = fts_ecc_check(dram_buf, dram_size, dram_start_addr); - if (ret < 0) { - FTS_ERROR("dram ecc check fail"); - return ret; - } - - FTS_INFO("dram data write successfully"); - return 0; -} - -static int fts_pram_start(void) -{ - int ret = 0; - u8 cmd = FTS_ROMBOOT_CMD_START_APP; - - FTS_INFO("remap to start pram"); - ret = fts_write(&cmd, 1); - if (ret < 0) { - FTS_ERROR("write start pram cmd fail"); - return ret; - } - - return 0; -} - -/* - * description: download fw to IC and run - * - * param - buf: const, fw data buffer - * len: length of fw - * - * return 0 if success, otherwise return error code - */ -int fts_fw_write_start(const u8 *buf, u32 len, bool need_reset) -{ - int ret = 0; - - FTS_INFO("begin to write and start fw(bin len:%d)", len); - fts_data->fw_is_running = false; - - if (need_reset) { - /* enter into boot environment */ - ret = fts_enter_into_boot(); - if (ret < 0) { - FTS_ERROR("enter into boot environment fail"); - return ret; - } - } - - /* write pram */ - ret = fts_pram_write_ecc(buf, len); - if (ret < 0) { - FTS_ERROR("write pram fail"); - return ret; - } - - /* write dram */ - ret = fts_dram_write_ecc(buf, len); - if (ret < 0) { - FTS_ERROR("write dram fail"); - return ret; - } - - /* remap pram and run fw */ - ret = fts_pram_start(); - if (ret < 0) { - FTS_ERROR("pram start fail"); - return ret; - } - - fts_data->fw_is_running = true; - FTS_INFO("fw download successfully"); - return 0; -} - diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_gesture.c b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_gesture.c deleted file mode 100755 index edeaf9833d8f..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_gesture.c +++ /dev/null @@ -1,486 +0,0 @@ -/* - * - * FocalTech TouchScreen driver. - * - * Copyright (c) 2012-2019, Focaltech Ltd. All rights reserved. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/***************************************************************************** -* -* File Name: focaltech_gestrue.c -* -* Author: Focaltech Driver Team -* -* Created: 2016-08-08 -* -* Abstract: -* -* Reference: -* -*****************************************************************************/ - -/***************************************************************************** -* 1.Included header files -*****************************************************************************/ -#include "focaltech_core.h" -#if FTS_GESTURE_EN -/****************************************************************************** -* Private constant and macro definitions using #define -*****************************************************************************/ -#define KEY_GESTURE_U KEY_U -#define KEY_GESTURE_UP KEY_UP -#define KEY_GESTURE_DOWN KEY_DOWN -#define KEY_GESTURE_LEFT KEY_LEFT -#define KEY_GESTURE_RIGHT KEY_RIGHT -#define KEY_GESTURE_O KEY_O -#define KEY_GESTURE_E KEY_E -#define KEY_GESTURE_M KEY_M -#define KEY_GESTURE_L KEY_L -#define KEY_GESTURE_W KEY_W -#define KEY_GESTURE_S KEY_S -#define KEY_GESTURE_V KEY_V -#define KEY_GESTURE_C KEY_C -#define KEY_GESTURE_Z KEY_Z - -#define GESTURE_LEFT 0x20 -#define GESTURE_RIGHT 0x21 -#define GESTURE_UP 0x22 -#define GESTURE_DOWN 0x23 -#define GESTURE_DOUBLECLICK 0x24 -#define GESTURE_O 0x30 -#define GESTURE_W 0x31 -#define GESTURE_M 0x32 -#define GESTURE_E 0x33 -#define GESTURE_L 0x44 -#define GESTURE_S 0x46 -#define GESTURE_V 0x54 -#define GESTURE_Z 0x41 -#define GESTURE_C 0x34 - -/***************************************************************************** -* Private enumerations, structures and unions using typedef -*****************************************************************************/ -/* -* gesture_id - mean which gesture is recognised -* point_num - points number of this gesture -* coordinate_x - All gesture point x coordinate -* coordinate_y - All gesture point y coordinate -* mode - gesture enable/disable, need enable by host -* - 1:enable gesture function(default) 0:disable -* active - gesture work flag, -* always set 1 when suspend, set 0 when resume -*/ -struct fts_gesture_st { - u8 gesture_id; - u8 point_num; - u16 coordinate_x[FTS_GESTURE_POINTS_MAX]; - u16 coordinate_y[FTS_GESTURE_POINTS_MAX]; - u8 mode; - u8 active; -}; - -/***************************************************************************** -* Static variables -*****************************************************************************/ -static struct fts_gesture_st fts_gesture_data; - -/***************************************************************************** -* Global variable or extern global variabls/functions -*****************************************************************************/ - -/***************************************************************************** -* Static function prototypes -*****************************************************************************/ -static ssize_t fts_gesture_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - int count = 0; - u8 val = 0; - struct input_dev *input_dev = fts_data->input_dev; - - mutex_lock(&input_dev->mutex); - fts_read_reg(FTS_REG_GESTURE_EN, &val); - count = snprintf(buf, PAGE_SIZE, "Gesture Mode:%s\n", - fts_gesture_data.mode ? "On" : "Off"); - count += snprintf(buf + count, PAGE_SIZE, "Reg(0xD0)=%d\n", val); - mutex_unlock(&input_dev->mutex); - - return count; -} - -static ssize_t fts_gesture_store( - struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - struct input_dev *input_dev = fts_data->input_dev; - mutex_lock(&input_dev->mutex); - if (FTS_SYSFS_ECHO_ON(buf)) { - FTS_DEBUG("enable gesture"); - fts_gesture_data.mode = ENABLE; - } else if (FTS_SYSFS_ECHO_OFF(buf)) { - FTS_DEBUG("disable gesture"); - fts_gesture_data.mode = DISABLE; - } - mutex_unlock(&input_dev->mutex); - - return count; -} - -static ssize_t fts_gesture_buf_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - int count = 0; - int i = 0; - struct input_dev *input_dev = fts_data->input_dev; - struct fts_gesture_st *gesture = &fts_gesture_data; - - mutex_lock(&input_dev->mutex); - count = snprintf(buf, PAGE_SIZE, "Gesture ID:%d\n", gesture->gesture_id); - count += snprintf(buf + count, PAGE_SIZE, "Gesture PointNum:%d\n", - gesture->point_num); - count += snprintf(buf + count, PAGE_SIZE, "Gesture Points Buffer:\n"); - - /* save point data,max:6 */ - for (i = 0; i < FTS_GESTURE_POINTS_MAX; i++) { - count += snprintf(buf + count, PAGE_SIZE, "%3d(%4d,%4d) ", i, - gesture->coordinate_x[i], gesture->coordinate_y[i]); - if ((i + 1) % 4 == 0) - count += snprintf(buf + count, PAGE_SIZE, "\n"); - } - count += snprintf(buf + count, PAGE_SIZE, "\n"); - mutex_unlock(&input_dev->mutex); - - return count; -} - -static ssize_t fts_gesture_buf_store( - struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - return -EPERM; -} - - -/* sysfs gesture node - * read example: cat fts_gesture_mode ---read gesture mode - * write example:echo 1 > fts_gesture_mode --- write gesture mode to 1 - * - */ -static DEVICE_ATTR(fts_gesture_mode, S_IRUGO | S_IWUSR, fts_gesture_show, - fts_gesture_store); -/* - * read example: cat fts_gesture_buf --- read gesture buf - */ -static DEVICE_ATTR(fts_gesture_buf, S_IRUGO | S_IWUSR, - fts_gesture_buf_show, fts_gesture_buf_store); - -static struct attribute *fts_gesture_mode_attrs[] = { - &dev_attr_fts_gesture_mode.attr, - &dev_attr_fts_gesture_buf.attr, - NULL, -}; - -static struct attribute_group fts_gesture_group = { - .attrs = fts_gesture_mode_attrs, -}; - -int fts_create_gesture_sysfs(struct device *dev) -{ - int ret = 0; - - ret = sysfs_create_group(&dev->kobj, &fts_gesture_group); - if (ret) { - FTS_ERROR("gesture sys node create fail"); - sysfs_remove_group(&dev->kobj, &fts_gesture_group); - return ret; - } - - return 0; -} - -static void fts_gesture_report(struct input_dev *input_dev, int gesture_id) -{ - int gesture; - - FTS_DEBUG("gesture_id:0x%x", gesture_id); - switch (gesture_id) { - case GESTURE_LEFT: - gesture = KEY_GESTURE_LEFT; - break; - case GESTURE_RIGHT: - gesture = KEY_GESTURE_RIGHT; - break; - case GESTURE_UP: - gesture = KEY_GESTURE_UP; - break; - case GESTURE_DOWN: - gesture = KEY_GESTURE_DOWN; - break; - case GESTURE_DOUBLECLICK: - gesture = KEY_GESTURE_U; - break; - case GESTURE_O: - gesture = KEY_GESTURE_O; - break; - case GESTURE_W: - gesture = KEY_GESTURE_W; - break; - case GESTURE_M: - gesture = KEY_GESTURE_M; - break; - case GESTURE_E: - gesture = KEY_GESTURE_E; - break; - case GESTURE_L: - gesture = KEY_GESTURE_L; - break; - case GESTURE_S: - gesture = KEY_GESTURE_S; - break; - case GESTURE_V: - gesture = KEY_GESTURE_V; - break; - case GESTURE_Z: - gesture = KEY_GESTURE_Z; - break; - case GESTURE_C: - gesture = KEY_GESTURE_C; - break; - default: - gesture = -1; - break; - } - /* report event key */ - if (gesture != -1) { - FTS_DEBUG("Gesture Code=%d", gesture); - input_report_key(input_dev, gesture, 1); - input_sync(input_dev); - input_report_key(input_dev, gesture, 0); - input_sync(input_dev); - } -} - -/***************************************************************************** -* Name: fts_gesture_readdata -* Brief: Read information about gesture: enable flag/gesture points..., if ges- -* ture enable, save gesture points' information, and report to OS. -* It will be called this function every intrrupt when FTS_GESTURE_EN = 1 -* -* gesture data length: 1(enable) + 1(reserve) + 2(header) + 6 * 4 -* Input: ts_data - global struct data -* data - gesture data buffer if non-flash, else NULL -* Output: -* Return: 0 - read gesture data successfully, the report data is gesture data -* 1 - tp not in suspend/gesture not enable in TP FW -* -Exx - error -*****************************************************************************/ -int fts_gesture_readdata(struct fts_ts_data *ts_data, u8 *data) -{ - int ret = 0; - int i = 0; - int index = 0; - u8 buf[FTS_GESTURE_DATA_LEN] = { 0 }; - struct input_dev *input_dev = ts_data->input_dev; - struct fts_gesture_st *gesture = &fts_gesture_data; - - if (!ts_data->suspended || (DISABLE == gesture->mode)) { - return 1; - } - - if (!data) { - FTS_ERROR("gesture data buffer is null"); - ret = -EINVAL; - return ret; - } - - memcpy(buf, data, FTS_GESTURE_DATA_LEN); - if (buf[0] != ENABLE) { - FTS_DEBUG("gesture not enable in fw, don't process gesture"); - return 1; - } - - - /* init variable before read gesture point */ - memset(gesture->coordinate_x, 0, FTS_GESTURE_POINTS_MAX * sizeof(u16)); - memset(gesture->coordinate_y, 0, FTS_GESTURE_POINTS_MAX * sizeof(u16)); - gesture->gesture_id = buf[2]; - gesture->point_num = buf[3]; - FTS_DEBUG("gesture_id=%d, point_num=%d", - gesture->gesture_id, gesture->point_num); - - /* save point data,max:6 */ - for (i = 0; i < FTS_GESTURE_POINTS_MAX; i++) { - index = 4 * i + 4; - gesture->coordinate_x[i] = (u16)(((buf[0 + index] & 0x0F) << 8) - + buf[1 + index]); - gesture->coordinate_y[i] = (u16)(((buf[2 + index] & 0x0F) << 8) - + buf[3 + index]); - } - - /* report gesture to OS */ - fts_gesture_report(input_dev, gesture->gesture_id); - return 0; -} - -void fts_gesture_recovery(struct fts_ts_data *ts_data) -{ - if ((ENABLE == fts_gesture_data.mode) && (ENABLE == fts_gesture_data.active)) { - FTS_DEBUG("gesture recovery..."); - fts_write_reg(0xD1, 0xFF); - fts_write_reg(0xD2, 0xFF); - fts_write_reg(0xD5, 0xFF); - fts_write_reg(0xD6, 0xFF); - fts_write_reg(0xD7, 0xFF); - fts_write_reg(0xD8, 0xFF); - fts_write_reg(FTS_REG_GESTURE_EN, ENABLE); - } -} - -int fts_gesture_suspend(struct fts_ts_data *ts_data) -{ - int ret = 0; - int i = 0; - u8 state = 0xFF; - - FTS_INFO("gesture suspend..."); - /* gesture not enable, return immediately */ - if (fts_gesture_data.mode == DISABLE) { - FTS_DEBUG("gesture is disabled"); - return -EINVAL; - } - - for (i = 0; i < 5; i++) { - fts_write_reg(0xD1, 0xFF); - fts_write_reg(0xD2, 0xFF); - fts_write_reg(0xD5, 0xFF); - fts_write_reg(0xD6, 0xFF); - fts_write_reg(0xD7, 0xFF); - fts_write_reg(0xD8, 0xFF); - fts_write_reg(FTS_REG_GESTURE_EN, ENABLE); - msleep(1); - fts_read_reg(FTS_REG_GESTURE_EN, &state); - if (state == ENABLE) - break; - } - - if (i >= 5) { - FTS_ERROR("Enter into gesture(suspend) fail"); - fts_gesture_data.active = DISABLE; - return -EIO; - } - - ret = enable_irq_wake(ts_data->irq); - if (ret) { - FTS_DEBUG("enable_irq_wake(irq:%d) fail", ts_data->irq); - } - - fts_gesture_data.active = ENABLE; - FTS_INFO("Enter into gesture(suspend) successfully!"); - return 0; -} - -int fts_gesture_resume(struct fts_ts_data *ts_data) -{ - int ret = 0; - int i = 0; - u8 state = 0xFF; - - FTS_INFO("gesture resume..."); - /* gesture not enable, return immediately */ - if (fts_gesture_data.mode == DISABLE) { - FTS_DEBUG("gesture is disabled"); - return -EINVAL; - } - - if (fts_gesture_data.active == DISABLE) { - FTS_DEBUG("gesture active is disable, return immediately"); - return -EINVAL; - } - - fts_gesture_data.active = DISABLE; - for (i = 0; i < 5; i++) { - fts_write_reg(FTS_REG_GESTURE_EN, DISABLE); - msleep(1); - fts_read_reg(FTS_REG_GESTURE_EN, &state); - if (state == DISABLE) - break; - } - - if (i >= 5) { - FTS_ERROR("exit gesture(resume) fail"); - return -EIO; - } - - ret = disable_irq_wake(ts_data->irq); - if (ret) { - FTS_DEBUG("disable_irq_wake(irq:%d) fail", ts_data->irq); - } - - FTS_INFO("resume from gesture successfully"); - return 0; -} - -int fts_gesture_init(struct fts_ts_data *ts_data) -{ - struct input_dev *input_dev = ts_data->input_dev; - - FTS_FUNC_ENTER(); - input_set_capability(input_dev, EV_KEY, KEY_POWER); - input_set_capability(input_dev, EV_KEY, KEY_GESTURE_U); - input_set_capability(input_dev, EV_KEY, KEY_GESTURE_UP); - input_set_capability(input_dev, EV_KEY, KEY_GESTURE_DOWN); - input_set_capability(input_dev, EV_KEY, KEY_GESTURE_LEFT); - input_set_capability(input_dev, EV_KEY, KEY_GESTURE_RIGHT); - input_set_capability(input_dev, EV_KEY, KEY_GESTURE_O); - input_set_capability(input_dev, EV_KEY, KEY_GESTURE_E); - input_set_capability(input_dev, EV_KEY, KEY_GESTURE_M); - input_set_capability(input_dev, EV_KEY, KEY_GESTURE_L); - input_set_capability(input_dev, EV_KEY, KEY_GESTURE_W); - input_set_capability(input_dev, EV_KEY, KEY_GESTURE_S); - input_set_capability(input_dev, EV_KEY, KEY_GESTURE_V); - input_set_capability(input_dev, EV_KEY, KEY_GESTURE_Z); - input_set_capability(input_dev, EV_KEY, KEY_GESTURE_C); - - __set_bit(KEY_GESTURE_RIGHT, input_dev->keybit); - __set_bit(KEY_GESTURE_LEFT, input_dev->keybit); - __set_bit(KEY_GESTURE_UP, input_dev->keybit); - __set_bit(KEY_GESTURE_DOWN, input_dev->keybit); - __set_bit(KEY_GESTURE_U, input_dev->keybit); - __set_bit(KEY_GESTURE_O, input_dev->keybit); - __set_bit(KEY_GESTURE_E, input_dev->keybit); - __set_bit(KEY_GESTURE_M, input_dev->keybit); - __set_bit(KEY_GESTURE_W, input_dev->keybit); - __set_bit(KEY_GESTURE_L, input_dev->keybit); - __set_bit(KEY_GESTURE_S, input_dev->keybit); - __set_bit(KEY_GESTURE_V, input_dev->keybit); - __set_bit(KEY_GESTURE_C, input_dev->keybit); - __set_bit(KEY_GESTURE_Z, input_dev->keybit); - - fts_create_gesture_sysfs(ts_data->dev); - - memset(&fts_gesture_data, 0, sizeof(struct fts_gesture_st)); - fts_gesture_data.mode = ENABLE; - fts_gesture_data.active = DISABLE; - - FTS_FUNC_EXIT(); - return 0; -} - -int fts_gesture_exit(struct fts_ts_data *ts_data) -{ - FTS_FUNC_ENTER(); - sysfs_remove_group(&ts_data->dev->kobj, &fts_gesture_group); - FTS_FUNC_EXIT(); - return 0; -} -#endif diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_point_report_check.c b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_point_report_check.c deleted file mode 100755 index 1296af1551db..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_point_report_check.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - * - * FocalTech TouchScreen driver. - * - * Copyright (c) 2012-2019, FocalTech Systems, Ltd., all rights reserved. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/***************************************************************************** -* -* File Name: focaltech_point_report_check.c -* -* Author: Focaltech Driver Team -* -* Created: 2016-11-16 -* -* Abstract: point report check function -* -* Version: v1.0 -* -* Revision History: -* -*****************************************************************************/ - -/***************************************************************************** -* Included header files -*****************************************************************************/ -#include "focaltech_core.h" - -#if FTS_POINT_REPORT_CHECK_EN -/***************************************************************************** -* Private constant and macro definitions using #define -*****************************************************************************/ -#define POINT_REPORT_CHECK_WAIT_TIME 200 /* unit:ms */ - -/***************************************************************************** -* functions body -*****************************************************************************/ -/***************************************************************************** -* Name: fts_prc_func -* Brief: fts point report check work func, report whole up of points -* Input: -* Output: -* Return: -*****************************************************************************/ -static void fts_prc_func(struct work_struct *work) -{ - struct fts_ts_data *ts_data = container_of(work, - struct fts_ts_data, prc_work.work); - struct input_dev *input_dev = ts_data->input_dev; -#if FTS_MT_PROTOCOL_B_EN - u32 finger_count = 0; - u32 max_touches = fts_data->pdata->max_touch_number; -#endif - - FTS_FUNC_ENTER(); - mutex_lock(&ts_data->report_mutex); - -#if FTS_MT_PROTOCOL_B_EN - for (finger_count = 0; finger_count < max_touches; finger_count++) { - input_mt_slot(input_dev, finger_count); - input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, false); - } -#else - input_mt_sync(input_dev); -#endif - input_report_key(input_dev, BTN_TOUCH, 0); - input_sync(input_dev); - - mutex_unlock(&ts_data->report_mutex); - - FTS_FUNC_EXIT(); -} - -/***************************************************************************** -* Name: fts_prc_queue_work -* Brief: fts point report check queue work, call it when interrupt comes -* Input: -* Output: -* Return: -*****************************************************************************/ -void fts_prc_queue_work(struct fts_ts_data *ts_data) -{ - cancel_delayed_work_sync(&ts_data->prc_work); - queue_delayed_work(ts_data->ts_workqueue, &ts_data->prc_work, - msecs_to_jiffies(POINT_REPORT_CHECK_WAIT_TIME)); -} - -/***************************************************************************** -* Name: fts_point_report_check_init -* Brief: -* Input: -* Output: -* Return: < 0: Fail to create esd check queue -*****************************************************************************/ -int fts_point_report_check_init(struct fts_ts_data *ts_data) -{ - FTS_FUNC_ENTER(); - - if (ts_data->ts_workqueue) { - INIT_DELAYED_WORK(&ts_data->prc_work, fts_prc_func); - } else { - FTS_ERROR("fts workqueue is NULL, can't run point report check function"); - return -EINVAL; - } - - FTS_FUNC_EXIT(); - return 0; -} - -/***************************************************************************** -* Name: fts_point_report_check_exit -* Brief: -* Input: -* Output: -* Return: -*****************************************************************************/ -int fts_point_report_check_exit(struct fts_ts_data *ts_data) -{ - FTS_FUNC_ENTER(); - - FTS_FUNC_EXIT(); - return 0; -} -#endif /* FTS_POINT_REPORT_CHECK_EN */ - diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_spi.c b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_spi.c deleted file mode 100755 index 6b2ac3500790..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_spi.c +++ /dev/null @@ -1,338 +0,0 @@ -/* - * - * FocalTech TouchScreen driver. - * - * Copyright (c) 2012-2019, FocalTech Systems, Ltd., all rights reserved. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/************************************************************************ -* -* File Name: focaltech_spi.c -* -* Author: FocalTech Driver Team -* -* Created: 2019-03-21 -* -* Abstract: new spi protocol communication with TP -* -* Version: v1.0 -* -* Revision History: -* -************************************************************************/ - -/***************************************************************************** -* Included header files -*****************************************************************************/ -#include "focaltech_core.h" - -/***************************************************************************** -* Private constant and macro definitions using #define -*****************************************************************************/ -#define SPI_RETRY_NUMBER 3 -#define CS_HIGH_DELAY 150 /* unit: us */ -#define SPI_BUF_LENGTH 256 - -#define DATA_CRC_EN 0x20 -#define WRITE_CMD 0x00 -#define READ_CMD (0x80 | DATA_CRC_EN) - -#define SPI_DUMMY_BYTE 3 -#define SPI_HEADER_LENGTH (SPI_DUMMY_BYTE + 6) -/***************************************************************************** -* Private enumerations, structures and unions using typedef -*****************************************************************************/ - -/***************************************************************************** -* Static variables -*****************************************************************************/ - -/***************************************************************************** -* Global variable or extern global variabls/functions -*****************************************************************************/ - -/***************************************************************************** -* Static function prototypes -*****************************************************************************/ - -/***************************************************************************** -* functions body -*****************************************************************************/ -/* spi interface */ -static int fts_spi_transfer(u8 *tx_buf, u8 *rx_buf, u32 len) -{ - int ret = 0; - struct spi_device *spi = fts_data->spi; - struct spi_message msg; - struct spi_transfer xfer = { - .tx_buf = tx_buf, - .rx_buf = rx_buf, - .len = len, - }; - - spi_message_init(&msg); - spi_message_add_tail(&xfer, &msg); - - ret = spi_sync(spi, &msg); - if (ret) { - FTS_ERROR("spi_sync fail,ret:%d", ret); - return ret; - } - - return ret; -} - -static void crckermit(u8 *data, u16 len, u16 *crc_out) -{ - u16 i = 0; - u16 j = 0; - u16 crc = 0xFFFF; - - for ( i = 0; i < len; i++) { - crc ^= data[i]; - for (j = 0; j < 8; j++) { - if (crc & 0x01) - crc = (crc >> 1) ^ 0x8408; - else - crc = (crc >> 1); - } - } - - *crc_out = crc; -} - -static int rdata_check(u8 *rdata, u32 rlen) -{ - u16 crc_calc = 0; - u16 crc_read = 0; - - crckermit(rdata, rlen - 2, &crc_calc); - crc_read = (u16)(rdata[rlen - 1] << 8) + rdata[rlen - 2]; - if (crc_calc != crc_read) { - return -EIO; - } - - return 0; -} - -int fts_write(u8 *writebuf, u32 writelen) -{ - int ret = 0; - int i = 0; - struct fts_ts_data *ts_data = fts_data; - u8 *txbuf = NULL; - u8 *rxbuf = NULL; - u32 txlen = 0; - u32 txlen_need = writelen + SPI_HEADER_LENGTH; - u32 datalen = writelen - 1; - - if (!writebuf || !writelen) { - FTS_ERROR("writebuf/len is invalid"); - return -EINVAL; - } - - mutex_lock(&ts_data->bus_lock); - if (txlen_need > SPI_BUF_LENGTH) { - txbuf = kzalloc(txlen_need, GFP_KERNEL); - if (NULL == txbuf) { - FTS_ERROR("txbuf malloc fail"); - ret = -ENOMEM; - goto err_write; - } - - rxbuf = kzalloc(txlen_need, GFP_KERNEL); - if (NULL == rxbuf) { - FTS_ERROR("rxbuf malloc fail"); - ret = -ENOMEM; - goto err_write; - } - } else { - txbuf = ts_data->bus_tx_buf; - rxbuf = ts_data->bus_rx_buf; - memset(txbuf, 0x0, SPI_BUF_LENGTH); - memset(rxbuf, 0x0, SPI_BUF_LENGTH); - } - - txbuf[txlen++] = writebuf[0]; - txbuf[txlen++] = WRITE_CMD; - txbuf[txlen++] = (datalen >> 8) & 0xFF; - txbuf[txlen++] = datalen & 0xFF; - if (datalen > 0) { - txlen = txlen + SPI_DUMMY_BYTE; - memcpy(&txbuf[txlen], &writebuf[1], datalen); - txlen = txlen + datalen; - } - - for (i = 0; i < SPI_RETRY_NUMBER; i++) { - ret = fts_spi_transfer(txbuf, rxbuf, txlen); - if ((0 == ret) && ((rxbuf[3] & 0xA0) == 0)) { - break; - } else { - FTS_DEBUG("data write(status=%x),retry=%d,ret=%d", - rxbuf[3], i, ret); - ret = -EIO; - udelay(CS_HIGH_DELAY); - } - } - -err_write: - if (txlen_need > SPI_BUF_LENGTH) { - if (txbuf) { - kfree(txbuf); - txbuf = NULL; - } - - if (rxbuf) { - kfree(rxbuf); - rxbuf = NULL; - } - } - - mutex_unlock(&ts_data->bus_lock); - return ret; -} - -int fts_write_reg(u8 addr, u8 value) -{ - u8 writebuf[2] = { 0 }; - - writebuf[0] = addr; - writebuf[1] = value; - return fts_write(writebuf, 2); -} - -int fts_read(u8 *cmd, u32 cmdlen, u8 *data, u32 datalen) -{ - int ret = 0; - int i = 0; - struct fts_ts_data *ts_data = fts_data; - u8 *txbuf = NULL; - u8 *rxbuf = NULL; - u32 txlen = 0; - u32 txlen_need = datalen + SPI_HEADER_LENGTH; - u8 ctrl = READ_CMD; - u32 dp = 0; - - if (!cmd || !cmdlen || !data || !datalen) { - FTS_ERROR("cmd/cmdlen/data/datalen is invalid"); - return -EINVAL; - } - - mutex_lock(&ts_data->bus_lock); - if (txlen_need > SPI_BUF_LENGTH) { - txbuf = kzalloc(txlen_need, GFP_KERNEL); - if (NULL == txbuf) { - FTS_ERROR("txbuf malloc fail"); - ret = -ENOMEM; - goto err_read; - } - - rxbuf = kzalloc(txlen_need, GFP_KERNEL); - if (NULL == rxbuf) { - FTS_ERROR("rxbuf malloc fail"); - ret = -ENOMEM; - goto err_read; - } - } else { - txbuf = ts_data->bus_tx_buf; - rxbuf = ts_data->bus_rx_buf; - memset(txbuf, 0x0, SPI_BUF_LENGTH); - memset(rxbuf, 0x0, SPI_BUF_LENGTH); - } - - txbuf[txlen++] = cmd[0]; - txbuf[txlen++] = ctrl; - txbuf[txlen++] = (datalen >> 8) & 0xFF; - txbuf[txlen++] = datalen & 0xFF; - dp = txlen + SPI_DUMMY_BYTE; - txlen = dp + datalen; - if (ctrl & DATA_CRC_EN) { - txlen = txlen + 2; - } - - for (i = 0; i < SPI_RETRY_NUMBER; i++) { - ret = fts_spi_transfer(txbuf, rxbuf, txlen); - if ((0 == ret) && ((rxbuf[3] & 0xA0) == 0)) { - memcpy(data, &rxbuf[dp], datalen); - /* crc check */ - if (ctrl & DATA_CRC_EN) { - ret = rdata_check(&rxbuf[dp], txlen - dp); - if (ret < 0) { - FTS_INFO("read data(addr:%x) crc check incorrect", cmd[0]); - goto err_read; - } - } - break; - } else { - FTS_DEBUG("data read(status=%x),retry=%d,ret=%d", - rxbuf[3], i, ret); - ret = -EIO; - udelay(CS_HIGH_DELAY); - } - } - -err_read: - if (txlen_need > SPI_BUF_LENGTH) { - if (txbuf) { - kfree(txbuf); - txbuf = NULL; - } - - if (rxbuf) { - kfree(rxbuf); - rxbuf = NULL; - } - } - - mutex_unlock(&ts_data->bus_lock); - return ret; -} - -int fts_read_reg(u8 addr, u8 *value) -{ - return fts_read(&addr, 1, value, 1); -} - -int fts_bus_init(struct fts_ts_data *ts_data) -{ - FTS_FUNC_ENTER(); - ts_data->bus_tx_buf = kzalloc(SPI_BUF_LENGTH, GFP_KERNEL); - if (NULL == ts_data->bus_tx_buf) { - FTS_ERROR("failed to allocate memory for bus_tx_buf"); - return -ENOMEM; - } - - ts_data->bus_rx_buf = kzalloc(SPI_BUF_LENGTH, GFP_KERNEL); - if (NULL == ts_data->bus_rx_buf) { - FTS_ERROR("failed to allocate memory for bus_rx_buf"); - return -ENOMEM; - } - FTS_FUNC_EXIT(); - return 0; -} - -int fts_bus_exit(struct fts_ts_data *ts_data) -{ - FTS_FUNC_ENTER(); - if (ts_data && ts_data->bus_tx_buf) { - kfree(ts_data->bus_tx_buf); - ts_data->bus_tx_buf = NULL; - } - - if (ts_data && ts_data->bus_rx_buf) { - kfree(ts_data->bus_rx_buf); - ts_data->bus_rx_buf = NULL; - } - FTS_FUNC_EXIT(); - return 0; -} diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/Makefile b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/Makefile deleted file mode 100755 index 062610eba31a..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -obj-$(CONFIG_TOUCHSCREEN_FTS) += focaltech_test.o -obj-$(CONFIG_TOUCHSCREEN_FTS) += focaltech_test_ini.o -obj-$(CONFIG_TOUCHSCREEN_FTS) += supported_ic/ diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/focaltech_test.c b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/focaltech_test.c deleted file mode 100755 index b1213d350d93..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/focaltech_test.c +++ /dev/null @@ -1,2050 +0,0 @@ -/* - * - * FocalTech TouchScreen driver. - * - * Copyright (c) 2012-2019, FocalTech Systems, Ltd., all rights reserved. - * - * This software is licensed under the terms of the GNU General Public - * License version 2, as published by the Free Software Foundation, and - * may be copied, distributed, and modified under those terms. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -/************************************************************************ -* -* File Name: focaltech_test.c -* -* Author: Focaltech Driver Team -* -* Created: 2016-08-01 -* -* Modify: -* -* Abstract: create char device and proc node for the comm between APK and TP -* -************************************************************************/ - -/***************************************************************************** -* Included header files -*****************************************************************************/ -#include "focaltech_test.h" - -/***************************************************************************** -* Private constant and macro definitions using #define -*****************************************************************************/ - -/***************************************************************************** -* Global variable or extern global variabls/functions -*****************************************************************************/ -struct fts_test *fts_ftest; - -struct test_funcs *test_func_list[] = { -#ifdef CONFIG_INPUT_FOCALTECH_0FLASH_MMI_IC_NAME_FT8719 - &test_func_ft8719, -#endif -#ifdef CONFIG_INPUT_FOCALTECH_0FLASH_MMI_IC_NAME_FT8756 - &test_func_ft8756, -#endif -}; - -/***************************************************************************** -* Static function prototypes -*****************************************************************************/ - -/***************************************************************************** -* functions body -*****************************************************************************/ -void sys_delay(int ms) -{ - msleep(ms); -} - -int focal_abs(int value) -{ - if (value < 0) - value = 0 - value; - - return value; -} - -void *fts_malloc(size_t size) -{ - return kzalloc(size, GFP_KERNEL); -} - -void fts_free_proc(void *p) -{ - return kfree(p); -} - -void print_buffer(int *buffer, int length, int line_num) -{ - int i = 0; - int j = 0; - int tmpline = 0; - char *tmpbuf = NULL; - int tmplen = 0; - int cnt = 0; - struct fts_test *tdata = fts_ftest; - - if (tdata && tdata->ts_data && (tdata->ts_data->log_level < 3)) { - return; - } - - if ((NULL == buffer) || (length <= 0)) { - FTS_TEST_DBG("buffer/length(%d) fail", length); - return; - } - - tmpline = line_num ? line_num : length; - tmplen = tmpline * 6 + 128; - tmpbuf = kzalloc(tmplen, GFP_KERNEL); - - for (i = 0; i < length; i = i + tmpline) { - cnt = 0; - for (j = 0; j < tmpline; j++) { - cnt += snprintf(tmpbuf + cnt, tmplen - cnt, "%5d ", buffer[i + j]); - if ((cnt >= tmplen) || ((i + j + 1) >= length)) - break; - } - FTS_TEST_DBG("%s", tmpbuf); - } - - if (tmpbuf) { - kfree(tmpbuf); - tmpbuf = NULL; - } -} - -/******************************************************************** - * test read/write interface - *******************************************************************/ -static int fts_test_bus_read( - u8 *cmd, int cmdlen, u8 *data, int datalen) -{ - int ret = 0; - - ret = fts_read(cmd, cmdlen, data, datalen); - if (ret < 0) - return ret; - else - return 0; -} - -static int fts_test_bus_write(u8 *writebuf, int writelen) -{ - int ret = 0; - - ret = fts_write(writebuf, writelen); - if (ret < 0) - return ret; - else - return 0; -} - -int fts_test_read_reg(u8 addr, u8 *val) -{ - return fts_test_bus_read(&addr, 1, val, 1); -} - -int fts_test_write_reg(u8 addr, u8 val) -{ - int ret; - u8 cmd[2] = {0}; - - cmd[0] = addr; - cmd[1] = val; - ret = fts_test_bus_write(cmd, 2); - - return ret; -} - -int fts_test_read(u8 addr, u8 *readbuf, int readlen) -{ - int ret = 0; - int i = 0; - int packet_length = 0; - int packet_num = 0; - int packet_remainder = 0; - int offset = 0; - int byte_num = readlen; - - packet_num = byte_num / BYTES_PER_TIME; - packet_remainder = byte_num % BYTES_PER_TIME; - if (packet_remainder) - packet_num++; - - if (byte_num < BYTES_PER_TIME) { - packet_length = byte_num; - } else { - packet_length = BYTES_PER_TIME; - } - /* FTS_TEST_DBG("packet num:%d, remainder:%d", packet_num, packet_remainder); */ - - ret = fts_test_bus_read(&addr, 1, &readbuf[offset], packet_length); - if (ret < 0) { - FTS_TEST_ERROR("read buffer fail"); - return ret; - } - for (i = 1; i < packet_num; i++) { - offset += packet_length; - if ((i == (packet_num - 1)) && packet_remainder) { - packet_length = packet_remainder; - } - - ret = fts_test_bus_read(&addr, 1, &readbuf[offset], - packet_length); - - if (ret < 0) { - FTS_TEST_ERROR("read buffer fail"); - return ret; - } - } - - return 0; -} - -int fts_test_write(u8 addr, u8 *writebuf, int writelen) -{ - int ret = 0; - int i = 0; - u8 *data = NULL; - int packet_length = 0; - int packet_num = 0; - int packet_remainder = 0; - int offset = 0; - int byte_num = writelen; - - data = fts_malloc(BYTES_PER_TIME + 1); - if (!data) { - FTS_TEST_ERROR("malloc memory for bus write data fail"); - return -ENOMEM; - } - - packet_num = byte_num / BYTES_PER_TIME; - packet_remainder = byte_num % BYTES_PER_TIME; - if (packet_remainder) - packet_num++; - - if (byte_num < BYTES_PER_TIME) { - packet_length = byte_num; - } else { - packet_length = BYTES_PER_TIME; - } - /* FTS_TEST_DBG("packet num:%d, remainder:%d", packet_num, packet_remainder); */ - - data[0] = addr; - for (i = 0; i < packet_num; i++) { - if (i != 0) { - data[0] = addr + 1; - } - if ((i == (packet_num - 1)) && packet_remainder) { - packet_length = packet_remainder; - } - memcpy(&data[1], &writebuf[offset], packet_length); - - ret = fts_test_bus_write(data, packet_length + 1); - if (ret < 0) { - FTS_TEST_ERROR("write buffer fail"); - fts_free(data); - return ret; - } - - offset += packet_length; - } - - fts_free(data); - return 0; -} - -/******************************************************************** - * test global function enter work/factory mode - *******************************************************************/ -int enter_work_mode(void) -{ - int ret = 0; - u8 mode = 0; - int i = 0; - int j = 0; - - FTS_TEST_FUNC_ENTER(); - - ret = fts_test_read_reg(DEVIDE_MODE_ADDR, &mode); - if ((ret >= 0) && (0x00 == mode)) - return 0; - - for (i = 0; i < ENTER_WORK_FACTORY_RETRIES; i++) { - ret = fts_test_write_reg(DEVIDE_MODE_ADDR, 0x00); - if (ret >= 0) { - sys_delay(FACTORY_TEST_DELAY); - for (j = 0; j < 20; j++) { - ret = fts_test_read_reg(DEVIDE_MODE_ADDR, &mode); - if ((ret >= 0) && (0x00 == mode)) { - FTS_TEST_INFO("enter work mode success"); - return 0; - } else - sys_delay(FACTORY_TEST_DELAY); - } - } - - sys_delay(50); - } - - if (i >= ENTER_WORK_FACTORY_RETRIES) { - FTS_TEST_ERROR("Enter work mode fail"); - return -EIO; - } - - FTS_TEST_FUNC_EXIT(); - return 0; -} - -int enter_factory_mode(void) -{ - int ret = 0; - u8 mode = 0; - int i = 0; - int j = 0; - - ret = fts_test_read_reg(DEVIDE_MODE_ADDR, &mode); - if ((ret >= 0) && (0x40 == mode)) - return 0; - - for (i = 0; i < ENTER_WORK_FACTORY_RETRIES; i++) { - ret = fts_test_write_reg(DEVIDE_MODE_ADDR, 0x40); - if (ret >= 0) { - sys_delay(FACTORY_TEST_DELAY); - for (j = 0; j < 20; j++) { - ret = fts_test_read_reg(DEVIDE_MODE_ADDR, &mode); - if ((ret >= 0) && (0x40 == mode)) { - FTS_TEST_INFO("enter factory mode success"); - sys_delay(200); - return 0; - } else - sys_delay(FACTORY_TEST_DELAY); - } - } - - sys_delay(50); - } - - if (i >= ENTER_WORK_FACTORY_RETRIES) { - FTS_TEST_ERROR("Enter factory mode fail"); - return -EIO; - } - - return 0; -} - -/* - * read_mass_data - read rawdata/short test data - * addr - register addr which read data from - * byte_num - read data length, unit:byte - * buf - save data - * - * return 0 if read data succuss, otherwise return error code - */ -int read_mass_data(u8 addr, int byte_num, int *buf) -{ - int ret = 0; - int i = 0; - u8 *data = NULL; - - data = (u8 *)fts_malloc(byte_num * sizeof(u8)); - if (NULL == data) { - FTS_TEST_SAVE_ERR("mass data buffer malloc fail\n"); - return -ENOMEM; - } - - /* read rawdata buffer */ - FTS_TEST_INFO("mass data len:%d", byte_num); - ret = fts_test_read(addr, data, byte_num); - if (ret < 0) { - FTS_TEST_SAVE_ERR("read mass data fail\n"); - goto read_massdata_err; - } - - for (i = 0; i < byte_num; i = i + 2) { - buf[i >> 1] = (int)(short)((data[i] << 8) + data[i + 1]); - } - - ret = 0; -read_massdata_err: - fts_free(data); - return ret; -} - -int short_get_adcdata_incell(u8 retval, u8 ch_num, int byte_num, int *adc_buf) -{ - int ret = 0; - int times = 0; - u8 short_state = 0; - - FTS_TEST_FUNC_ENTER(); - - /* Start ADC sample */ - ret = fts_test_write_reg(FACTORY_REG_SHORT_TEST_EN, 0x01); - if (ret) { - FTS_TEST_SAVE_ERR("start short test fail\n"); - goto adc_err; - } - - sys_delay(ch_num * FACTORY_TEST_DELAY); - for (times = 0; times < FACTORY_TEST_RETRY; times++) { - ret = fts_test_read_reg(FACTORY_REG_SHORT_TEST_STATE, &short_state); - if ((ret >= 0) && (retval == short_state)) - break; - else - FTS_TEST_DBG("reg%x=%x,retry:%d", - FACTORY_REG_SHORT_TEST_STATE, short_state, times); - - sys_delay(FACTORY_TEST_RETRY_DELAY); - } - if (times >= FACTORY_TEST_RETRY) { - FTS_TEST_SAVE_ERR("short test timeout, ADC data not OK\n"); - ret = -EIO; - goto adc_err; - } - - ret = read_mass_data(FACTORY_REG_SHORT_ADDR, byte_num, adc_buf); - if (ret) { - FTS_TEST_SAVE_ERR("get short(adc) data fail\n"); - } - -adc_err: - FTS_TEST_FUNC_EXIT(); - return ret; -} - -/* - * wait_state_update - wait fw status update - */ -int wait_state_update(u8 retval) -{ - int ret = 0; - int times = 0; - u8 state = 0xFF; - - while (times++ < FACTORY_TEST_RETRY) { - sys_delay(FACTORY_TEST_DELAY); - /* Wait register status update */ - state = 0xFF; - ret = fts_test_read_reg(FACTORY_REG_PARAM_UPDATE_STATE, &state); - if ((ret >= 0) && (retval == state)) - break; - else - FTS_TEST_DBG("reg%x=%x,retry:%d", \ - FACTORY_REG_PARAM_UPDATE_STATE, state, times); - } - - if (times >= FACTORY_TEST_RETRY) { - FTS_TEST_SAVE_ERR("Wait State Update fail\n"); - return -EIO; - } - - return 0; -} - -/* - * start_scan - start to scan a frame - */ -int start_scan(void) -{ - int ret = 0; - u8 addr = 0; - u8 val = 0; - u8 finish_val = 0; - int times = 0; - struct fts_test *tdata = fts_ftest; - - if ((NULL == tdata) || (NULL == tdata->func)) { - FTS_TEST_SAVE_ERR("test/func is null\n"); - return -EINVAL; - } - - if (SCAN_SC == tdata->func->startscan_mode) { - /* sc ic */ - addr = FACTORY_REG_SCAN_ADDR2; - val = 0x01; - finish_val = 0x00; - } else { - addr = DEVIDE_MODE_ADDR; - val = 0xC0; - finish_val = 0x40; - } - - /* write register to start scan */ - ret = fts_test_write_reg(addr, val); - if (ret < 0) { - FTS_TEST_SAVE_ERR("write start scan mode fail\n"); - return ret; - } - - /* Wait for the scan to complete */ - while (times++ < FACTORY_TEST_RETRY) { - sys_delay(FACTORY_TEST_DELAY); - - ret = fts_test_read_reg(addr, &val); - if ((ret >= 0) && (val == finish_val)) { - break; - } else - FTS_TEST_DBG("reg%x=%x,retry:%d", addr, val, times); - } - - if (times >= FACTORY_TEST_RETRY) { - FTS_TEST_SAVE_ERR("scan timeout\n"); - return -EIO; - } - - return 0; -} - -static int read_rawdata( - u8 off_addr, - u8 off_val, - u8 rawdata_addr, - int byte_num, - int *data) -{ - int ret = 0; - - /* set line addr or rawdata start addr */ - ret = fts_test_write_reg(off_addr, off_val); - if (ret < 0) { - FTS_TEST_SAVE_ERR("wirte line/start addr fail\n"); - return ret; - } - - ret = read_mass_data(rawdata_addr, byte_num, data); - if (ret < 0) { - FTS_TEST_SAVE_ERR("read rawdata fail\n"); - return ret; - } - - return 0; -} - -int get_rawdata(int *data) -{ - int ret = 0; - u8 val = 0; - u8 addr = 0; - u8 rawdata_addr = 0; - int byte_num = 0; - struct fts_test *tdata = fts_ftest; - - if ((NULL == tdata) || (NULL == tdata->func)) { - FTS_TEST_SAVE_ERR("test/func is null\n"); - return -EINVAL; - } - - /* enter factory mode */ - ret = enter_factory_mode(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("failed to enter factory mode,ret=%d\n", ret); - return ret; - } - - /* start scanning */ - ret = start_scan(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("scan fail\n"); - return ret; - } - - /* read rawdata */ - if (IC_HW_INCELL == tdata->func->hwtype) { - val = 0xAD; - addr = FACTORY_REG_LINE_ADDR; - rawdata_addr = FACTORY_REG_RAWDATA_ADDR; - } else if (IC_HW_MC_SC == tdata->func->hwtype) { - val = 0xAA; - addr = FACTORY_REG_LINE_ADDR; - rawdata_addr = FACTORY_REG_RAWDATA_ADDR_MC_SC; - } else { - val = 0x0; - addr = FACTORY_REG_RAWDATA_SADDR_SC; - rawdata_addr = FACTORY_REG_RAWDATA_ADDR_SC; - } - - byte_num = tdata->node.node_num * 2; - ret = read_rawdata(addr, val, rawdata_addr, byte_num, data); - if (ret < 0) { - FTS_TEST_SAVE_ERR("read rawdata fail\n"); - return ret; - } - - return 0; -} - -/* - * chip_clb - auto clb - */ -int chip_clb(void) -{ - int ret = 0; - u8 val = 0; - int times = 0; - - /* start clb */ - ret = fts_test_write_reg(FACTORY_REG_CLB, 0x04); - if (ret) { - FTS_TEST_SAVE_ERR("write start clb fail\n"); - return ret; - } - - while (times++ < FACTORY_TEST_RETRY) { - sys_delay(FACTORY_TEST_RETRY_DELAY); - ret = fts_test_read_reg(FACTORY_REG_CLB, &val); - if ((0 == ret) && (0x02 == val)) { - /* clb ok */ - break; - } else - FTS_TEST_DBG("reg%x=%x,retry:%d", FACTORY_REG_CLB, val, times); - } - - if (times >= FACTORY_TEST_RETRY) { - FTS_TEST_SAVE_ERR("chip clb timeout\n"); - return -EIO; - } - - return 0; -} - -/* - * get_cb_incell - get cb data for incell IC - */ -int get_cb_incell(u16 saddr, int byte_num, int *cb_buf) -{ - int ret = 0; - int i = 0; - u8 cb_addr = 0; - u8 addr_h = 0; - u8 addr_l = 0; - int read_num = 0; - int packet_num = 0; - int packet_remainder = 0; - int offset = 0; - int addr = 0; - u8 *data = NULL; - - data = (u8 *)fts_malloc(byte_num * sizeof(u8)); - if (NULL == data) { - FTS_TEST_SAVE_ERR("cb buffer malloc fail\n"); - return -ENOMEM; - } - - packet_num = byte_num / BYTES_PER_TIME; - packet_remainder = byte_num % BYTES_PER_TIME; - if (packet_remainder) - packet_num++; - read_num = BYTES_PER_TIME; - - FTS_TEST_INFO("cb packet:%d,remainder:%d", packet_num, packet_remainder); - cb_addr = FACTORY_REG_CB_ADDR; - for (i = 0; i < packet_num; i++) { - offset = read_num * i; - addr = saddr + offset; - addr_h = (addr >> 8) & 0xFF; - addr_l = addr & 0xFF; - if ((i == (packet_num - 1)) && packet_remainder) { - read_num = packet_remainder; - } - - ret = fts_test_write_reg(FACTORY_REG_CB_ADDR_H, addr_h); - if (ret) { - FTS_TEST_SAVE_ERR("write cb addr high fail\n"); - goto TEST_CB_ERR; - } - ret = fts_test_write_reg(FACTORY_REG_CB_ADDR_L, addr_l); - if (ret) { - FTS_TEST_SAVE_ERR("write cb addr low fail\n"); - goto TEST_CB_ERR; - } - - ret = fts_test_read(cb_addr, data + offset, read_num); - if (ret) { - FTS_TEST_SAVE_ERR("read cb fail\n"); - goto TEST_CB_ERR; - } - } - - for (i = 0; i < byte_num; i++) { - cb_buf[i] = data[i]; - } - -TEST_CB_ERR: - fts_free(data); - return ret; -} - -int get_cb_sc(int byte_num, int *cb_buf, enum byte_mode mode) -{ - int ret = 0; - int i = 0; - int read_num = 0; - int packet_num = 0; - int packet_remainder = 0; - int offset = 0; - u8 cb_addr = 0; - u8 off_addr = 0; - struct fts_test *tdata = fts_ftest; - u8 *cb = NULL; - - if ((NULL == tdata) || (NULL == tdata->func)) { - FTS_TEST_SAVE_ERR("test/func is null\n"); - return -EINVAL; - } - - cb = (u8 *)fts_malloc(byte_num * sizeof(u8)); - if (NULL == cb) { - FTS_TEST_SAVE_ERR("malloc memory for cb buffer fail\n"); - return -ENOMEM; - } - - if (IC_HW_MC_SC == tdata->func->hwtype) { - cb_addr = FACTORY_REG_MC_SC_CB_ADDR; - off_addr = FACTORY_REG_MC_SC_CB_ADDR_OFF; - } else if (IC_HW_SC == tdata->func->hwtype) { - cb_addr = FACTORY_REG_SC_CB_ADDR; - off_addr = FACTORY_REG_SC_CB_ADDR_OFF; - } - - packet_num = byte_num / BYTES_PER_TIME; - packet_remainder = byte_num % BYTES_PER_TIME; - if (packet_remainder) - packet_num++; - read_num = BYTES_PER_TIME; - offset = 0; - - FTS_TEST_INFO("cb packet:%d,remainder:%d", packet_num, packet_remainder); - for (i = 0; i < packet_num; i++) { - if ((i == (packet_num - 1)) && packet_remainder) { - read_num = packet_remainder; - } - - ret = fts_test_write_reg(off_addr, offset); - if (ret < 0) { - FTS_TEST_SAVE_ERR("write cb addr offset fail\n"); - goto cb_err; - } - - ret = fts_test_read(cb_addr, cb + offset, read_num); - if (ret < 0) { - FTS_TEST_SAVE_ERR("read cb fail\n"); - goto cb_err; - } - - offset += read_num; - } - - if (DATA_ONE_BYTE == mode) { - for (i = 0; i < byte_num; i++) { - cb_buf[i] = cb[i]; - } - } else if (DATA_TWO_BYTE == mode) { - for (i = 0; i < byte_num; i = i + 2) { - cb_buf[i >> 1] = (int)(((int)(cb[i]) << 8) + cb[i + 1]); - } - } - - ret = 0; -cb_err: - fts_free(cb); - return ret; -} - -bool compare_data(int *data, int min, int max, int min_vk, int max_vk, bool key) -{ - int i = 0; - bool result = true; - struct fts_test *tdata = fts_ftest; - int rx = tdata->node.rx_num; - int node_va = tdata->node.node_num - tdata->node.key_num; - - if (!data || !tdata->node_valid) { - FTS_TEST_SAVE_ERR("data/node_valid is null\n"); - return false; - } - - for (i = 0; i < node_va; i++) { - if (0 == tdata->node_valid[i]) - continue; - - if ((data[i] < min) || (data[i] > max)) { - FTS_TEST_SAVE_ERR("test fail,node(%4d,%4d)=%5d,range=(%5d,%5d)\n", - i / rx + 1, i % rx + 1, data[i], min, max); - result = false; - } - } - - if (key) { - for (i = node_va; i < tdata->node.node_num; i++) { - if (0 == tdata->node_valid[i]) - continue; - - if ((data[i] < min_vk) || (data[i] > max_vk)) { - FTS_TEST_SAVE_ERR("test fail,node(%4d,%4d)=%5d,range=(%5d,%5d)\n", - i / rx + 1, i % rx + 1, - data[i], min_vk, max_vk); - result = false; - } - } - } - - return result; -} - -bool compare_array(int *data, int *min, int *max, bool key) -{ - int i = 0; - bool result = true; - struct fts_test *tdata = fts_ftest; - int rx = tdata->node.rx_num; - int node_num = tdata->node.node_num; - - if (!data || !min || !max || !tdata->node_valid) { - FTS_TEST_SAVE_ERR("data/min/max/node_valid is null\n"); - return false; - } - - if (!key) { - node_num -= tdata->node.key_num; - } - for (i = 0; i < node_num; i++) { - if (0 == tdata->node_valid[i]) - continue; - - if ((data[i] < min[i]) || (data[i] > max[i])) { - FTS_TEST_SAVE_ERR("test fail,node(%4d,%4d)=%5d,range=(%5d,%5d)\n", - i / rx + 1, i % rx + 1, data[i], min[i], max[i]); - result = false; - } - } - - return result; -} - -/* - * show_data - show and save test data to testresult.txt - */ -void show_data(int *data, bool key) -{ -#if TXT_SUPPORT - int i = 0; - int j = 0; - struct fts_test *tdata = fts_ftest; - int node_num = tdata->node.node_num; - int tx_num = tdata->node.tx_num; - int rx_num = tdata->node.rx_num; - - FTS_TEST_FUNC_ENTER(); - for (i = 0; i < tx_num; i++) { - FTS_TEST_SAVE_INFO("Ch/Tx_%02d: ", i + 1); - for (j = 0; j < rx_num; j++) { - FTS_TEST_SAVE_INFO("%5d, ", data[i * rx_num + j]); - } - FTS_TEST_SAVE_INFO("\n"); - } - - if (key) { - FTS_TEST_SAVE_INFO("Ch/Tx_%02d: ", tx_num + 1); - for (i = tx_num * rx_num; i < node_num; i++) { - FTS_TEST_SAVE_INFO("%5d, ", data[i]); - } - FTS_TEST_SAVE_INFO("\n"); - } - FTS_TEST_FUNC_EXIT(); -#endif -} - -/* mc_sc only */ -/* Only V3 Pattern has mapping & no-mapping */ -int mapping_switch(u8 mapping) -{ - int ret = 0; - u8 val = 0xFF; - struct fts_test *tdata = fts_ftest; - - if (tdata->v3_pattern) { - ret = fts_test_read_reg(FACTORY_REG_NOMAPPING, &val); - if (ret < 0) { - FTS_TEST_ERROR("read 0x54 register fail"); - return ret; - } - - if (val != mapping) { - ret = fts_test_write_reg(FACTORY_REG_NOMAPPING, mapping); - if (ret < 0) { - FTS_TEST_ERROR("write 0x54 register fail"); - return ret; - } - sys_delay(FACTORY_TEST_DELAY); - } - } - - return 0; -} - -bool get_fw_wp(u8 wp_ch_sel, enum wp_type water_proof_type) -{ - bool fw_wp_state = false; - - switch (water_proof_type) { - case WATER_PROOF_ON: - /* bit5: 0-check in wp on, 1-not check */ - fw_wp_state = !(wp_ch_sel & 0x20); - break; - case WATER_PROOF_ON_TX: - /* Bit6: 0-check Rx+Tx in wp mode 1-check one channel - Bit2: 0-check Tx in wp mode; 1-check Rx in wp mode - */ - fw_wp_state = (!(wp_ch_sel & 0x40) || !(wp_ch_sel & 0x04)); - break; - case WATER_PROOF_ON_RX: - fw_wp_state = (!(wp_ch_sel & 0x40) || (wp_ch_sel & 0x04)); - break; - case WATER_PROOF_OFF: - /* bit7: 0-check in wp off, 1-not check */ - fw_wp_state = !(wp_ch_sel & 0x80); - break; - case WATER_PROOF_OFF_TX: - /* Bit1-0: 00-check Tx in non-wp mode - 01-check Rx in non-wp mode - 10:check Rx+Tx in non-wp mode - */ - fw_wp_state = ((0x0 == (wp_ch_sel & 0x03)) || (0x02 == (wp_ch_sel & 0x03))); - break; - case WATER_PROOF_OFF_RX: - fw_wp_state = ((0x01 == (wp_ch_sel & 0x03)) || (0x02 == (wp_ch_sel & 0x03))); - break; - default: - break; - } - - return fw_wp_state; -} - -int get_cb_mc_sc(u8 wp, int byte_num, int *cb_buf, enum byte_mode mode) -{ - int ret = 0; - - /* 1:waterproof 0:non-waterproof */ - ret = fts_test_write_reg(FACTORY_REG_MC_SC_MODE, wp); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get mc_sc mode fail\n"); - return ret; - } - - /* read cb */ - ret = get_cb_sc(byte_num, cb_buf, mode); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get sc cb fail\n"); - return ret; - } - - return 0; -} - -int get_rawdata_mc_sc(enum wp_type wp, int *data) -{ - int ret = 0; - u8 val = 0; - u8 addr = 0; - u8 rawdata_addr = 0; - int byte_num = 0; - struct fts_test *tdata = fts_ftest; - - if ((NULL == tdata) || (NULL == tdata->func)) { - FTS_TEST_SAVE_ERR("test/func is null\n"); - return -EINVAL; - } - - addr = FACTORY_REG_LINE_ADDR; - rawdata_addr = FACTORY_REG_RAWDATA_ADDR_MC_SC; - if (WATER_PROOF_ON == wp) { - val = 0xAC; - } else { - val = 0xAB; - } - - byte_num = tdata->sc_node.node_num * 2; - ret = read_rawdata(addr, val, rawdata_addr, byte_num, data); - if (ret < 0) { - FTS_TEST_SAVE_ERR("read rawdata fail\n"); - return ret; - } - - return 0; -} - -int get_rawdata_mc(u8 fre, u8 fir, int *rawdata) -{ - int ret = 0; - int i = 0; - - if (NULL == rawdata ) { - FTS_TEST_SAVE_ERR("rawdata buffer is null\n"); - return -EINVAL; - } - - /* set frequecy high/low */ - ret = fts_test_write_reg(FACTORY_REG_FRE_LIST, fre); - if (ret < 0) { - FTS_TEST_SAVE_ERR("set frequecy fail,ret=%d\n", ret); - return ret; - } - - /* fir enable/disable */ - ret = fts_test_write_reg(FACTORY_REG_FIR, fir); - if (ret < 0) { - FTS_TEST_SAVE_ERR("set fir fail,ret=%d\n", ret); - return ret; - } - - /* get rawdata */ - for (i = 0; i < 3; i++) { - /* lost 3 frames, in order to obtain stable data */ - ret = get_rawdata(rawdata); - } - if (ret < 0) { - FTS_TEST_SAVE_ERR("get rawdata fail,ret=%d\n", ret); - return ret; - } - - return 0; -} - -int short_get_adc_data_mc(u8 retval, int byte_num, int *adc_buf, u8 mode) -{ - int ret = 0; - int i = 0; - u8 short_state = 0; - - FTS_TEST_FUNC_ENTER(); - /* select short test mode & start test */ - ret = fts_test_write_reg(FACTROY_REG_SHORT_TEST_EN, mode); - if (ret < 0) { - FTS_TEST_SAVE_ERR("write short test mode fail\n"); - goto test_err; - } - - for (i = 0; i < FACTORY_TEST_RETRY; i++) { - sys_delay(FACTORY_TEST_RETRY_DELAY); - - ret = fts_test_read_reg(FACTROY_REG_SHORT_TEST_EN, &short_state); - if ((ret >= 0) && (retval == short_state)) - break; - else - FTS_TEST_DBG("reg%x=%x,retry:%d", - FACTROY_REG_SHORT_TEST_EN, short_state, i); - } - if (i >= FACTORY_TEST_RETRY) { - FTS_TEST_SAVE_ERR("short test timeout, ADC data not OK\n"); - ret = -EIO; - goto test_err; - } - - ret = read_mass_data(FACTORY_REG_SHORT_ADDR_MC, byte_num, adc_buf); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get short(adc) data fail\n"); - } - - FTS_TEST_DBG("adc data:\n"); - print_buffer(adc_buf, byte_num / 2, 0); -test_err: - FTS_TEST_FUNC_EXIT(); - return ret; -} - -bool compare_mc_sc(bool tx_check, bool rx_check, int *data, int *min, int *max) -{ - int i = 0; - bool result = true; - struct fts_test *tdata = fts_ftest; - - if (rx_check) { - for (i = 0; i < tdata->sc_node.rx_num; i++) { - if (0 == tdata->node_valid_sc[i]) - continue; - - if ((data[i] < min[i]) || (data[i] > max[i])) { - FTS_TEST_SAVE_ERR("test fail,rx%d=%5d,range=(%5d,%5d)\n", - i + 1, data[i], min[i], max[i]); - result = false; - } - } - } - - if (tx_check) { - for (i = tdata->sc_node.rx_num; i < tdata->sc_node.node_num; i++) { - if (0 == tdata->node_valid_sc[i]) - continue; - - if ((data[i] < min[i]) || (data[i] > max[i])) { - FTS_TEST_SAVE_INFO("test fail,tx%d=%5d,range=(%5d,%5d)\n", - i - tdata->sc_node.rx_num + 1, - data[i], min[i], max[i]); - result = false; - } - } - } - - return result; -} - -void show_data_mc_sc(int *data) -{ - int i = 0; - struct fts_test *tdata = fts_ftest; - - FTS_TEST_SAVE_INFO("SCap Rx: "); - for (i = 0; i < tdata->sc_node.rx_num; i++) { - FTS_TEST_SAVE_INFO( "%5d, ", data[i]); - } - FTS_TEST_SAVE_INFO("\n"); - - FTS_TEST_SAVE_INFO("SCap Tx: "); - for (i = tdata->sc_node.rx_num; i < tdata->sc_node.node_num; i++) { - FTS_TEST_SAVE_INFO( "%5d, ", data[i]); - } - FTS_TEST_SAVE_INFO("\n"); -} -/* mc_sc end*/ - -#if CSV_SUPPORT || TXT_SUPPORT -static int fts_test_save_test_data(char *file_name, char *data_buf, int len) -{ - struct file *pfile = NULL; - char filepath[128]; - loff_t pos; - mm_segment_t old_fs; - - FTS_TEST_FUNC_ENTER(); - memset(filepath, 0, sizeof(filepath)); - sprintf(filepath, "%s%s", FTS_INI_FILE_PATH, file_name); - if (NULL == pfile) { - pfile = filp_open(filepath, O_TRUNC | O_CREAT | O_RDWR, 0); - } - if (IS_ERR(pfile)) { - FTS_TEST_ERROR("error occured while opening file %s.", filepath); - return -EIO; - } - - old_fs = get_fs(); - set_fs(KERNEL_DS); - pos = 0; - vfs_write(pfile, data_buf, len, &pos); - filp_close(pfile, NULL); - set_fs(old_fs); - - FTS_TEST_FUNC_EXIT(); - return 0; -} -#endif - -static int fts_test_malloc_free_data_txt(struct fts_test *tdata, bool allocate) -{ -#if TXT_SUPPORT - if (true == allocate) { - tdata->testresult = vmalloc(TXT_BUFFER_LEN); - if (NULL == tdata->testresult) { - FTS_TEST_ERROR("tdata->testresult malloc fail\n"); - return -ENOMEM; - } - - tdata->testresult_len = 0; - FTS_TEST_SAVE_INFO("FW version:0x%02x\n", tdata->fw_ver); - FTS_TEST_SAVE_INFO("tx_num:%d, rx_num:%d, key_num:%d\n", - tdata->node.tx_num, tdata->node.rx_num, - tdata->node.key_num); - } else { - if (tdata->testresult) { - vfree(tdata->testresult); - tdata->testresult = NULL; - } - } -#endif - return 0; -} - -static void fts_test_save_data_csv(struct fts_test *tdata) -{ -#if CSV_SUPPORT - int i = 0; - int j = 0; - int k = 0; - int tx = 0; - int rx = 0; - int node_num = 0; - int offset = 0; - int start_line = 11; - int data_count = 0; - char *csv_buffer = NULL; - char *line2_buffer = NULL; - int csv_length = 0; - int line2_length = 0; - int csv_item_count = 0; - struct fts_test_data *td = &tdata->testdata; - struct item_info *info = NULL; - - FTS_TEST_INFO("save data in csv format"); - csv_buffer = vmalloc(CSV_BUFFER_LEN); - if (!csv_buffer) { - FTS_TEST_ERROR("csv_buffer malloc fail\n"); - return ; - } - - line2_buffer = vmalloc(CSV_LINE2_BUFFER_LEN); - if (!line2_buffer) { - FTS_TEST_ERROR("line2_buffer malloc fail\n"); - goto csv_save_err; - } - - FTS_TEST_INFO("test item count:%d", td->item_count); - /* line 1 */ - csv_length += snprintf(csv_buffer + csv_length, \ - CSV_BUFFER_LEN - csv_length, \ - "ECC, 85, 170, IC Name, %s, IC Code, %x\n", \ - tdata->ini.ic_name, \ - (tdata->ini.ic_code >> IC_CODE_OFFSET)); - - /* line 2 */ - for (i = 0; i < td->item_count; i++) { - info = &td->info[i]; - if (info->mc_sc) { - node_num = tdata->sc_node.node_num; - /* set max len of tx/rx to column */ - rx = (tdata->sc_node.tx_num > tdata->sc_node.rx_num) - ? tdata->sc_node.tx_num : tdata->sc_node.rx_num; - } else { - if (info->key_support && (tdata->node.key_num > 0)) - node_num = (tdata->node.tx_num + 1) * tdata->node.rx_num; - else - node_num = tdata->node.tx_num * tdata->node.rx_num; - rx = tdata->node.rx_num; - } - - if (info->datalen > node_num) { - data_count = (info->datalen - 1 ) / node_num + 1; - tx = (node_num - 1 ) / rx + 1; - } else { - data_count = 1; - tx = ((info->datalen - 1) / rx) + 1; - } - - for (j = 1; j <= data_count; j++) { - line2_length += snprintf(line2_buffer + line2_length, \ - CSV_LINE2_BUFFER_LEN - line2_length, \ - "%s, %d, %d, %d, %d, %d, ", \ - info->name, info->code, tx, rx, - start_line, j); - start_line += tx; - csv_item_count++; - } - } - - csv_length += snprintf(csv_buffer + csv_length, \ - CSV_BUFFER_LEN - csv_length, \ - "TestItem Num, %d, ", \ - csv_item_count); - - if (line2_length > 0) { - csv_length += snprintf(csv_buffer + csv_length, \ - CSV_BUFFER_LEN - csv_length, \ - "%s", line2_buffer); - } - - /* line 3 ~ 10 "\n" */ - csv_length += snprintf(csv_buffer + csv_length, \ - CSV_BUFFER_LEN - csv_length, \ - "\n\n\n\n\n\n\n\n\n"); - - /* line 11 ~ data area */ - for (i = 0; i < td->item_count; i++) { - info = &td->info[i]; - if (!info->data) { - FTS_TEST_ERROR("test item data is null"); - return; - } - - if (info->mc_sc) { - offset = 0; - for (j = 0; j < info->datalen; j++) { - for (k = 0; k < tdata->sc_node.node_num; k++) { - csv_length += snprintf(csv_buffer + csv_length, \ - CSV_BUFFER_LEN - csv_length, \ - "%d, ", info->data[offset + k]); - if ((k + 1) == tdata->sc_node.rx_num) { - csv_length += snprintf(csv_buffer + csv_length, \ - CSV_BUFFER_LEN - csv_length, \ - "\n"); - } - } - csv_length += snprintf(csv_buffer + csv_length, \ - CSV_BUFFER_LEN - csv_length, \ - "\n"); - offset += k; - j += k; - } - } else { - for (j = 0; j < info->datalen; j++) { - csv_length += snprintf(csv_buffer + csv_length, \ - CSV_BUFFER_LEN - csv_length, \ - "%d, ", info->data[j]); - if (((j + 1) % tdata->node.rx_num) == 0) { - csv_length += snprintf(csv_buffer + csv_length, \ - CSV_BUFFER_LEN - csv_length, - "\n"); - } - } - } - } - FTS_TEST_INFO("csv length:%d", csv_length); - fts_test_save_test_data(FTS_CSV_FILE_NAME, csv_buffer, csv_length); - -csv_save_err: - if (csv_buffer) { - vfree(csv_buffer); - csv_buffer = NULL; - } -#endif -} - -static void fts_test_save_result_txt(struct fts_test *tdata) -{ -#if TXT_SUPPORT - if (!tdata || !tdata->testresult) { - FTS_TEST_ERROR("test result is null"); - return; - } - - FTS_TEST_INFO("test result length in txt:%d", tdata->testresult_len); - fts_test_save_test_data(FTS_TXT_FILE_NAME, tdata->testresult, - tdata->testresult_len); -#endif -} - -/***************************************************************************** -* Name: fts_test_save_data -* Brief: Save test data. -* If multi-data of MC, length of data package must be tx*rx,(tx+1)*rx -* If multi-data of MC-SC, length of data package should be (tx+rx)*2 -* Need fill 0 when no actual data -* Input: -* Output: -* Return: -*****************************************************************************/ -void fts_test_save_data(char *name, int code, int *data, int datacnt, - bool mc_sc, bool key, bool result) -{ - int datalen = datacnt; - struct fts_test *tdata = fts_ftest; - struct fts_test_data *td = &tdata->testdata; - struct item_info *info = &td->info[td->item_count]; - - if (!name || !data) { - FTS_TEST_ERROR("name/data is null"); - return ; - } - - strncpy(info->name, name, TEST_ITEM_NAME_MAX); - info->code = code; - info->mc_sc = mc_sc; - info->key_support = key; - info->result = result; - if (datalen <= 0) { - if (mc_sc) { - datalen = tdata->sc_node.node_num * 2; - } else { - if (key && (tdata->node.key_num > 0)) - datalen = (tdata->node.tx_num + 1) * tdata->node.rx_num; - else - datalen = tdata->node.tx_num * tdata->node.rx_num; - - } - } - - FTS_TEST_DBG("name:%s,len:%d", name, datalen); - info->data = fts_malloc(datalen * sizeof(int)); - if (!info->data) { - FTS_TEST_ERROR("malloc memory for item(%d) data fail", td->item_count); - info->datalen = 0; - return ; - } - memcpy(info->data, data, datalen * sizeof(int)); - info->datalen = datalen; - - td->item_count++; -} - -static void fts_test_free_data(struct fts_test *tdata) -{ - int i = 0; - struct fts_test_data *td = &tdata->testdata; - - for (i = 0; i < td->item_count; i++) { - if (td->info[i].data) { - fts_free(td->info[i].data); - } - } -} - -static int fts_test_malloc_free_incell(struct fts_test *tdata, bool allocate) -{ - struct incell_threshold *thr = &tdata->ic.incell.thr; - int buflen = tdata->node.node_num * sizeof(int); - - if (true == allocate) { - FTS_TEST_INFO("buflen:%d", buflen); - fts_malloc_r(thr->rawdata_min, buflen); - fts_malloc_r(thr->rawdata_max, buflen); - if (tdata->func->rawdata2_support) { - fts_malloc_r(thr->rawdata2_min, buflen); - fts_malloc_r(thr->rawdata2_max, buflen); - } - fts_malloc_r(thr->cb_min, buflen); - fts_malloc_r(thr->cb_max, buflen); - } else { - fts_free(thr->rawdata_min); - fts_free(thr->rawdata_max); - if (tdata->func->rawdata2_support) { - fts_free(thr->rawdata2_min); - fts_free(thr->rawdata2_max); - } - fts_free(thr->cb_min); - fts_free(thr->cb_max); - } - - return 0; -} - -static int fts_test_malloc_free_mc_sc(struct fts_test *tdata, bool allocate) -{ - struct mc_sc_threshold *thr = &tdata->ic.mc_sc.thr; - int buflen = tdata->node.node_num * sizeof(int); - int buflen_sc = tdata->sc_node.node_num * sizeof(int); - - if (true == allocate) { - fts_malloc_r(thr->rawdata_h_min, buflen); - fts_malloc_r(thr->rawdata_h_max, buflen); - if (tdata->func->rawdata2_support) { - fts_malloc_r(thr->rawdata_l_min, buflen); - fts_malloc_r(thr->rawdata_l_max, buflen); - } - fts_malloc_r(thr->tx_linearity_max, buflen); - fts_malloc_r(thr->tx_linearity_min, buflen); - fts_malloc_r(thr->rx_linearity_max, buflen); - fts_malloc_r(thr->rx_linearity_min, buflen); - - fts_malloc_r(thr->scap_cb_off_min, buflen_sc); - fts_malloc_r(thr->scap_cb_off_max, buflen_sc); - fts_malloc_r(thr->scap_cb_on_min, buflen_sc); - fts_malloc_r(thr->scap_cb_on_max, buflen_sc); - - fts_malloc_r(thr->scap_rawdata_off_min, buflen_sc); - fts_malloc_r(thr->scap_rawdata_off_max, buflen_sc); - fts_malloc_r(thr->scap_rawdata_on_min, buflen_sc); - fts_malloc_r(thr->scap_rawdata_on_max, buflen_sc); - - fts_malloc_r(thr->panel_differ_min, buflen); - fts_malloc_r(thr->panel_differ_max, buflen); - } else { - fts_free(thr->rawdata_h_min); - fts_free(thr->rawdata_h_max); - if (tdata->func->rawdata2_support) { - fts_free(thr->rawdata_l_min); - fts_free(thr->rawdata_l_max); - } - fts_free(thr->tx_linearity_max); - fts_free(thr->tx_linearity_min); - fts_free(thr->rx_linearity_max); - fts_free(thr->rx_linearity_min); - - fts_free(thr->scap_cb_off_min); - fts_free(thr->scap_cb_off_max); - fts_free(thr->scap_cb_on_min); - fts_free(thr->scap_cb_on_max); - - fts_free(thr->scap_rawdata_off_min); - fts_free(thr->scap_rawdata_off_max); - fts_free(thr->scap_rawdata_on_min); - fts_free(thr->scap_rawdata_on_max); - - fts_free(thr->panel_differ_min); - fts_free(thr->panel_differ_max); - } - - return 0; -} - -static int fts_test_malloc_free_sc(struct fts_test *tdata, bool allocate) -{ - struct sc_threshold *thr = &tdata->ic.sc.thr; - int buflen = tdata->node.node_num * sizeof(int); - - if (true == allocate) { - fts_malloc_r(thr->rawdata_min, buflen); - fts_malloc_r(thr->rawdata_max, buflen); - fts_malloc_r(thr->cb_min, buflen); - fts_malloc_r(thr->cb_max, buflen); - fts_malloc_r(thr->dcb_sort, buflen); - fts_malloc_r(thr->dcb_base, buflen); - } else { - fts_free(thr->rawdata_min); - fts_free(thr->rawdata_max); - fts_free(thr->cb_min); - fts_free(thr->cb_max); - fts_free(thr->dcb_sort); - fts_free(thr->dcb_base); - } - - return 0; -} - -static int fts_test_malloc_free_thr(struct fts_test *tdata, bool allocate) -{ - int ret = 0; - - if ((NULL == tdata) || (NULL == tdata->func)) { - FTS_TEST_SAVE_ERR("tdata/func is NULL\n"); - return -EINVAL; - } - - if (true == allocate) { - fts_malloc_r(tdata->node_valid, tdata->node.node_num * sizeof(int)); - fts_malloc_r(tdata->node_valid_sc, tdata->sc_node.node_num * sizeof(int)); - } else { - fts_free(tdata->node_valid); - fts_free(tdata->node_valid_sc); - } - - switch (tdata->func->hwtype) { - case IC_HW_INCELL: - ret = fts_test_malloc_free_incell(tdata, allocate); - break; - case IC_HW_MC_SC: - ret = fts_test_malloc_free_mc_sc(tdata, allocate); - break; - case IC_HW_SC: - ret = fts_test_malloc_free_sc(tdata, allocate); - break; - default: - FTS_TEST_SAVE_ERR("test ic type(%d) fail\n", tdata->func->hwtype); - ret = -EINVAL; - break; - } - - return ret; -} - -/* default enable all test item */ -static void fts_test_init_item(struct fts_test *tdata) -{ - switch (tdata->func->hwtype) { - case IC_HW_INCELL: - tdata->ic.incell.u.tmp = 0xFFFFFFFF; - break; - case IC_HW_MC_SC: - tdata->ic.mc_sc.u.tmp = 0xFFFFFFFF; - break; - case IC_HW_SC: - tdata->ic.sc.u.tmp = 0xFFFFFFFF; - break; - } -} - -static int get_tx_rx_num(u8 tx_rx_reg, u8 *ch_num, u8 ch_num_max) -{ - int ret = 0; - int i = 0; - - for (i = 0; i < 3; i++) { - ret = fts_test_read_reg(tx_rx_reg, ch_num); - if ((ret < 0) || (*ch_num > ch_num_max)) { - sys_delay(50); - } else - break; - } - - if (i >= 3) { - FTS_TEST_ERROR("get channel num fail"); - return -EIO; - } - - return 0; -} -static int get_key_num(int *key_num_en, int max_key_num) -{ - int ret = 0; - u8 key_en = 0; - - if (!max_key_num) { - FTS_TEST_DBG("not support key, don't read key num register"); - return 0; - } - - ret = fts_test_read_reg(FACTORY_REG_LEFT_KEY, &key_en); - if (ret >= 0) { - if (key_en & 0x01) { - (*key_num_en)++; - } - - if (key_en & 0x02) { - (*key_num_en)++; - } - - if (key_en & 0x04) { - (*key_num_en)++; - } - } - - ret = fts_test_read_reg(FACTORY_REG_RIGHT_KEY, &key_en); - if (ret >= 0) { - if (key_en & 0x01) { - (*key_num_en)++; - } - - if (key_en & 0x02) { - (*key_num_en)++; - } - - if (key_en & 0x04) { - (*key_num_en)++; - } - } - - if (*key_num_en > max_key_num) { - FTS_TEST_ERROR("get key num, fw:%d > max:%d", *key_num_en, max_key_num); - return -EIO; - } - - return ret; -} - -static int get_channel_num(struct fts_test *tdata) -{ - int ret = 0; - u8 tx_num = 0; - u8 rx_num = 0; - int key_num = 0; - - /* node structure */ - if (IC_HW_SC == tdata->func->hwtype) { - ret = get_tx_rx_num(FACTORY_REG_CH_NUM_SC, &tx_num, NUM_MAX_SC); - if (ret < 0) { - FTS_TEST_ERROR("get channel number fail"); - return ret; - } - - ret = get_tx_rx_num(FACTORY_REG_KEY_NUM_SC, &rx_num, KEY_NUM_MAX); - if (ret < 0) { - FTS_TEST_ERROR("get key number fail"); - return ret; - } - - tdata->node.tx_num = 2; - tdata->node.rx_num = tx_num / 2; - tdata->node.channel_num = tx_num; - tdata->node.node_num = tx_num; - key_num = rx_num; - } else { - ret = get_tx_rx_num(FACTORY_REG_CHX_NUM, &tx_num, TX_NUM_MAX); - if (ret < 0) { - FTS_TEST_ERROR("get tx_num fail"); - return ret; - } - - ret = get_tx_rx_num(FACTORY_REG_CHY_NUM, &rx_num, RX_NUM_MAX); - if (ret < 0) { - FTS_TEST_ERROR("get rx_num fail"); - return ret; - } - - if (IC_HW_INCELL == tdata->func->hwtype) { - ret = get_key_num(&key_num, tdata->func->key_num_total); - if (ret < 0) { - FTS_TEST_ERROR("get key_num fail"); - return ret; - } - } else if (IC_HW_MC_SC == tdata->func->hwtype) { - key_num = tdata->func->key_num_total; - } - tdata->node.tx_num = tx_num; - tdata->node.rx_num = rx_num; - if (IC_HW_INCELL == tdata->func->hwtype) - tdata->node.channel_num = tx_num * rx_num; - else if (IC_HW_MC_SC == tdata->func->hwtype) - tdata->node.channel_num = tx_num + rx_num; - tdata->node.node_num = tx_num * rx_num; - } - - /* key */ - tdata->node.key_num = key_num; - tdata->node.node_num += tdata->node.key_num; - - /* sc node structure */ - tdata->sc_node = tdata->node; - if (IC_HW_MC_SC == tdata->func->hwtype) { - if (tdata->v3_pattern) { - ret = get_tx_rx_num(FACTORY_REG_CHX_NUM_NOMAP, &tx_num, TX_NUM_MAX); - if (ret < 0) { - FTS_TEST_ERROR("get no-mappint tx_num fail"); - return ret; - } - - ret = get_tx_rx_num(FACTORY_REG_CHY_NUM_NOMAP, &rx_num, TX_NUM_MAX); - if (ret < 0) { - FTS_TEST_ERROR("get no-mapping rx_num fail"); - return ret; - } - - tdata->sc_node.tx_num = tx_num; - tdata->sc_node.rx_num = rx_num; - } - tdata->sc_node.channel_num = tx_num + rx_num; - tdata->sc_node.node_num = tx_num + rx_num; - } - - if (tdata->node.tx_num > TX_NUM_MAX) { - FTS_TEST_ERROR("tx num(%d) fail", tdata->node.tx_num); - return -EIO; - } - - if (tdata->node.rx_num > RX_NUM_MAX) { - FTS_TEST_ERROR("rx num(%d) fail", tdata->node.rx_num); - return -EIO; - } - - FTS_TEST_INFO("node_num:%d, tx:%d, rx:%d, key:%d", - tdata->node.node_num, tdata->node.tx_num, - tdata->node.rx_num, tdata->node.key_num); - return 0; -} - -static int fts_test_init_basicinfo(struct fts_test *tdata) -{ - int ret = 0; - u8 val = 0; - - if ((NULL == tdata) || (NULL == tdata->func)) { - FTS_TEST_SAVE_ERR("tdata/func is NULL\n"); - return -EINVAL; - } - - fts_test_read_reg(REG_FW_VERSION, &val); - tdata->fw_ver = val; - - if (IC_HW_INCELL == tdata->func->hwtype) { - fts_test_read_reg(REG_VA_TOUCH_THR, &val); - tdata->va_touch_thr = val; - fts_test_read_reg(REG_VKEY_TOUCH_THR, &val); - tdata->vk_touch_thr = val; - } - - /* enter factory mode */ - ret = enter_factory_mode(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("enter factory mode fail\n"); - return ret; - } - - if (IC_HW_MC_SC == tdata->func->hwtype) { - fts_test_read_reg(FACTORY_REG_PATTERN, &val); - tdata->v3_pattern = (1 == val) ? true : false; - fts_test_read_reg(FACTORY_REG_NOMAPPING, &val); - tdata->mapping = val; - } - - /* enter into factory mode and read tx/rx num */ - ret = get_channel_num(tdata); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get channel number fail\n"); - return ret; - } - - return ret; -} - -static int fts_test_main_init(void) -{ - int ret = 0; - struct fts_test *tdata = fts_ftest; - - FTS_TEST_FUNC_ENTER(); - /* Init fts_test_data to 0 before test, */ - memset(&tdata->testdata, 0, sizeof(struct fts_test_data)); - - /* get basic information: tx/rx num ... */ - ret = fts_test_init_basicinfo(tdata); - if (ret < 0) { - FTS_TEST_ERROR("test init basicinfo fail"); - return ret; - } - - /* allocate memory for test threshold */ - ret = fts_test_malloc_free_thr(tdata, true); - if (ret < 0) { - FTS_TEST_ERROR("test malloc for threshold fail"); - return ret; - } - - /* default enable all test item */ - fts_test_init_item(tdata); - - ret = fts_test_malloc_free_data_txt(tdata, true); - if (ret < 0) { - FTS_TEST_ERROR("allocate memory for test data(txt) fail"); - return ret; - } - - /* allocate test data buffer */ - tdata->buffer_length = (tdata->node.tx_num + 1) * tdata->node.rx_num; - tdata->buffer_length *= sizeof(int) * 2; - FTS_TEST_INFO("test buffer length:%d", tdata->buffer_length); - tdata->buffer = (int *)fts_malloc(tdata->buffer_length); - if (NULL == tdata->buffer) { - FTS_TEST_ERROR("test buffer(%d) malloc fail", tdata->buffer_length); - return -ENOMEM; - } - memset(tdata->buffer, 0, tdata->buffer_length); - - FTS_TEST_FUNC_EXIT(); - return ret; -} - -static int fts_test_main_exit(void) -{ - struct fts_test *tdata = fts_ftest; - - FTS_TEST_FUNC_ENTER(); - fts_test_save_data_csv(tdata); - fts_test_save_result_txt(tdata); - - /* free memory */ - fts_test_malloc_free_data_txt(tdata, false); - fts_test_malloc_free_thr(tdata, false); - - /* free test data */ - fts_test_free_data(tdata); - - /*free test data buffer*/ - fts_free(tdata->buffer); - - FTS_TEST_FUNC_EXIT(); - return 0; -} - - -/* - * fts_test_get_testparams - get test parameter from ini - */ -static int fts_test_get_testparams(char *config_name) -{ - int ret = 0; - - ret = fts_test_get_testparam_from_ini(config_name); - - return ret; -} - -static int fts_test_start(void) -{ - int testresult = 0; - struct fts_test *tdata = fts_ftest; - - tdata->testdata.item_count = 0; - if (tdata && tdata->func && tdata->func->start_test) { - testresult = tdata->func->start_test(); - } else { - FTS_TEST_ERROR("test func/start_test func is null"); - } - - return testresult; -} - -/* - * fts_test_entry - test main entry - * - * warning - need disable irq & esdcheck before call this function - * - */ -static int fts_test_entry(char *ini_file_name) -{ - int ret = 0; - - /* test initialize */ - ret = fts_test_main_init(); - if (ret < 0) { - FTS_TEST_ERROR("fts_test_main_init fail"); - goto test_err; - } - - /*Read parse configuration file*/ - FTS_TEST_SAVE_INFO("ini_file_name:%s\n", ini_file_name); - ret = fts_test_get_testparams(ini_file_name); - if (ret < 0) { - FTS_TEST_ERROR("get testparam fail"); - goto test_err; - } - - /* Start testing according to the test configuration */ - if (true == fts_test_start()) { - FTS_TEST_SAVE_INFO("\n\n=======Tp test pass.\n"); - } else { - FTS_TEST_SAVE_INFO("\n\n=======Tp test failure.\n"); - } - - ret = 0; -test_err: - fts_test_main_exit(); - enter_work_mode(); - return ret; -} - -static ssize_t fts_test_show( - struct device *dev, struct device_attribute *attr, char *buf) -{ - return -EPERM; -} - -static ssize_t fts_test_store( - struct device *dev, - struct device_attribute *attr, const char *buf, size_t count) -{ - int ret = 0; - char fwname[128] = {0}; - struct fts_ts_data *ts_data = fts_data; - struct input_dev *input_dev; - - if (ts_data->suspended) { - FTS_INFO("In suspend, no test, return now"); - return -EINVAL; - } - - input_dev = ts_data->input_dev; - memset(fwname, 0, sizeof(fwname)); - sprintf(fwname, "%s", buf); - fwname[count - 1] = '\0'; - FTS_TEST_DBG("fwname:%s.", fwname); - - mutex_lock(&input_dev->mutex); - disable_irq(ts_data->irq); - -#if defined(FTS_ESDCHECK_EN) && (FTS_ESDCHECK_EN) - fts_esdcheck_switch(DISABLE); -#endif - - ret = fts_enter_test_environment(1); - if (ret < 0) { - FTS_ERROR("enter test environment fail"); - } else { - fts_test_entry(fwname); - } - ret = fts_enter_test_environment(0); - if (ret < 0) { - FTS_ERROR("enter normal environment fail"); - } - -#if defined(FTS_ESDCHECK_EN) && (FTS_ESDCHECK_EN) - fts_esdcheck_switch(ENABLE); -#endif - - enable_irq(ts_data->irq); - mutex_unlock(&input_dev->mutex); - - return count; -} - -/* test from test.ini -* example:echo "***.ini" > fts_test -*/ -static DEVICE_ATTR(fts_test, S_IRUGO | S_IWUSR, fts_test_show, fts_test_store); - -static struct attribute *fts_test_attributes[] = { - &dev_attr_fts_test.attr, - NULL -}; - -static struct attribute_group fts_test_attribute_group = { - .attrs = fts_test_attributes -}; - -static int fts_test_func_init(struct fts_ts_data *ts_data) -{ - int i = 0; - int j = 0; - int ic_stype = ts_data->ic_info.ids.type; - struct test_funcs *func = test_func_list[0]; - int func_count = sizeof(test_func_list) / sizeof(test_func_list[0]); - - FTS_TEST_INFO("init test function"); - if (0 == func_count) { - FTS_TEST_SAVE_ERR("test functions list is NULL, fail\n"); - return -ENODATA; - } - - fts_ftest = (struct fts_test *)kzalloc(sizeof(*fts_ftest), GFP_KERNEL); - if (NULL == fts_ftest) { - FTS_TEST_ERROR("malloc memory for test fail"); - return -ENOMEM; - } - - for (i = 0; i < func_count; i++) { - func = test_func_list[i]; - for (j = 0; j < FTX_MAX_COMPATIBLE_TYPE; j++) { - if (0 == func->ctype[j]) - break; - else if (func->ctype[j] == ic_stype) { - FTS_TEST_INFO("match test function,type:%x", (int)func->ctype[j]); - fts_ftest->func = func; - } - } - } - if (NULL == fts_ftest->func) { - FTS_TEST_ERROR("no test function match, can't test"); - return -ENODATA; - } - - fts_ftest->ts_data = fts_data; - return 0; -} - -int fts_test_init(struct fts_ts_data *ts_data) -{ - int ret = 0; - - FTS_TEST_FUNC_ENTER(); - /* get test function, must be the first step */ - ret = fts_test_func_init(ts_data); - if (ret < 0) { - FTS_TEST_SAVE_ERR("test functions init fail"); - return ret; - } - - ret = sysfs_create_group(&ts_data->dev->kobj, &fts_test_attribute_group); - if (0 != ret) { - FTS_TEST_ERROR("sysfs(test) create fail"); - sysfs_remove_group(&ts_data->dev->kobj, &fts_test_attribute_group); - } else { - FTS_TEST_DBG("sysfs(test) create successfully"); - } - FTS_TEST_FUNC_EXIT(); - - return ret; -} - -int fts_test_exit(struct fts_ts_data *ts_data) -{ - FTS_TEST_FUNC_ENTER(); - - sysfs_remove_group(&ts_data->dev->kobj, &fts_test_attribute_group); - fts_free(fts_ftest); - FTS_TEST_FUNC_EXIT(); - return 0; -} diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/focaltech_test.h b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/focaltech_test.h deleted file mode 100755 index 3074352b48fd..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/focaltech_test.h +++ /dev/null @@ -1,602 +0,0 @@ -/************************************************************************ -* Copyright (C) 2012-2019, Focaltech Systems (R)£¬All Rights Reserved. -* -* File Name: focaltech_test.h -* -* Author: Focaltech Driver Team -* -* Created: 2016-08-01 -* -* Abstract: test entry for all IC -* -************************************************************************/ -#ifndef _TEST_LIB_H -#define _TEST_LIB_H - -/***************************************************************************** -* Included header files -*****************************************************************************/ - -#include -#include -#include -#include -#include -#include //iic -#include //msleep -#include -#include -#include - -#include "../focaltech_core.h" -#include "focaltech_test_ini.h" - -/***************************************************************************** -* Macro definitions using #define -*****************************************************************************/ -#define FTS_INI_FILE_PATH "/mnt/sdcard/" -#define FTS_CSV_FILE_NAME "testdata.csv" -#define FTS_TXT_FILE_NAME "testresult.txt" -#define false 0 -#define true 1 -#define TEST_ICSERIES_LEN (8) -#define TEST_ICSERIES(x) ((x) >> TEST_ICSERIES_LEN) - -#define TEST_OPEN_MAX_VALUE (255) -#define BYTES_PER_TIME (32) /* max:128 */ -/* CSV & TXT */ -#define CSV_LINE2_BUFFER_LEN (1024) -#define CSV_BUFFER_LEN (1024*80*5) -#define TXT_BUFFER_LEN (1024*80*5) - -/*----------------------------------------------------------- -Test Status ------------------------------------------------------------*/ -#define RESULT_NULL 0 -#define RESULT_PASS 1 -#define RESULT_NG 2 - -#define TX_NUM_MAX 60 -#define RX_NUM_MAX 60 -#define NUM_MAX ((TX_NUM_MAX)*(RX_NUM_MAX)) -#define NUM_MAX_SC (144) -#define KEY_NUM_MAX 6 -#define TEST_ITEM_COUNT_MAX 32 -#define TEST_ITEM_NAME_MAX 32 -#define TEST_SHORT_RES_MAX 0xFFFF - -/* - * factory test registers - */ -#define ENTER_WORK_FACTORY_RETRIES 5 - -#define START_SCAN_RETRIES_INCELL 20 -#define START_SCAN_RETRIES_DELAY_INCELL 16 -#define FACTORY_TEST_RETRY 50 -#define FACTORY_TEST_DELAY 18 -#define FACTORY_TEST_RETRY_DELAY 100 - -#define DEVIDE_MODE_ADDR 0x00 -#define REG_FW_VERSION 0xA6 -#define REG_VA_TOUCH_THR 0x80 -#define REG_VKEY_TOUCH_THR 0x82 - -#define FACTORY_REG_LINE_ADDR 0x01 -#define FACTORY_REG_CHX_NUM 0x02 -#define FACTORY_REG_CHY_NUM 0x03 -#define FACTORY_REG_CLB 0x04 -#define FACTORY_REG_DATA_SELECT 0x06 -#define FACTORY_REG_RAWBUF_SELECT 0x09 -#define FACTORY_REG_KEY_CBWIDTH 0x0B -#define FACTORY_REG_PARAM_UPDATE_STATE 0x0E -#define FACTORY_REG_SHORT_TEST_EN 0x0F -#define FACTORY_REG_SHORT_TEST_STATE 0x10 -#define FACTORY_REG_LCD_NOISE_START 0x11 -#define FACTORY_REG_LCD_NOISE_FRAME 0x12 -#define FACTORY_REG_LCD_NOISE_NUMBER 0x13 -#define FACTORY_REG_LCD_NOISE_TEST_STATE 0x13 -#define FACTORY_REG_LCD_NOISE_TTHR 0x14 -#define FACTORY_REG_OPEN_START 0x15 -#define FACTORY_REG_OPEN_STATE 0x16 -#define FACTORY_REG_OPEN_IDLE 0x03 -#define FACTORY_REG_OPEN_BUSY 0x01 -#define FACTORY_REG_CB_ADDR_H 0x18 -#define FACTORY_REG_CB_ADDR_L 0x19 -#define FACTORY_REG_ORDER_ADDR_H 0x1A -#define FACTORY_REG_ORDER_ADDR_L 0x1B -#define FACTORY_REG_LCD_NOISE_STATE 0x1E -#define FACTORY_REG_KEYSHORT_EN 0x2E -#define FACTORY_REG_KEYSHORT_STATE 0x2F - -#define FACTORY_REG_LEFT_KEY 0x1E -#define FACTORY_REG_RIGHT_KEY 0x1F -#define FACTORY_REG_OPEN_REG20 0x20 -#define FACTORY_REG_OPEN_REG21 0x21 -#define FACTORY_REG_OPEN_REG22 0x22 -#define FACTORY_REG_OPEN_REG23 0x23 -#define FACTORY_REG_OPEN_REG2E 0x2E -#define FACTORY_REG_OPEN_REG86 0x86 -#define FACTORY_REG_K1 0x31 -#define FACTORY_REG_K2 0x32 -#define FACTORY_REG_RAWDATA_ADDR 0x6A -#define FACTORY_REG_ORDER_ADDR 0x6C -#define FACTORY_REG_CB_ADDR 0x6E -#define FACTORY_REG_SHORT_ADDR 0x89 -#define FACTORY_REG_RAWDATA_TEST_EN 0x9E -#define FACTORY_REG_CB_TEST_EN 0x9F -#define FACTORY_REG_OPEN_TEST_EN 0xA0 - -/* mc_sc */ -#define FACTORY_REG_FRE_LIST 0x0A -#define FACTORY_REG_NORMALIZE 0x16 -#define FACTORY_REG_RAWDATA_ADDR_MC_SC 0x36 -#define FACTORY_REG_PATTERN 0x53 -#define FACTORY_REG_NOMAPPING 0x54 -#define FACTORY_REG_CHX_NUM_NOMAP 0x55 -#define FACTORY_REG_CHY_NUM_NOMAP 0x56 -#define FACTORY_REG_WC_SEL 0x09 -#define FACTORY_REG_MC_SC_MODE 0x44 -#define FACTORY_REG_MC_SC_CB_ADDR_OFF 0x45 -#define FACTORY_REG_MC_SC_CB_ADDR 0x4E -#define FACTROY_REG_SHORT_TEST_EN 0x07 -#define FACTROY_REG_SHORT_CA 0x01 -#define FACTROY_REG_SHORT_CC 0x02 -#define FACTROY_REG_SHORT_CG 0x03 -#define FACTROY_REG_SHORT_OFFSET 0x04 -#define FACTROY_REG_SHORT_AB_CH 0x58 -#define FACTROY_REG_SHORT_DELAY 0x5A -#define FACTORY_REG_SHORT_ADDR_MC 0xF4 -#define FACTORY_REG_FIR 0xFB - -/* sc */ -#define FACTORY_REG_SCAN_ADDR2 0x08 -#define FACTORY_REG_CH_NUM_SC 0x0A -#define FACTORY_REG_KEY_NUM_SC 0x0B -#define FACTORY_REG_SC_CB_ADDR_OFF 0x33 -#define FACTORY_REG_SC_CB_ADDR 0x39 -#define FACTORY_REG_RAWDATA_SADDR_SC 0x34 -#define FACTORY_REG_RAWDATA_ADDR_SC 0x35 -#define FACTORY_REG_CB_SEL 0x41 -#define FACTORY_REG_FMODE 0xAE - -#define TEST_RETVAL_00 0x00 -#define TEST_RETVAL_AA 0xAA - -/***************************************************************************** -* enumerations, structures and unions -*****************************************************************************/ -struct item_info { - char name[TEST_ITEM_NAME_MAX]; - int code; - int *data; - int datalen; - int result; - int mc_sc; - int key_support; -}; - -struct fts_test_data { - int item_count; - struct item_info info[TEST_ITEM_COUNT_MAX]; -}; - -/* incell */ -struct incell_testitem { - u32 short_test : 1; - u32 open_test : 1; - u32 cb_test : 1; - u32 rawdata_test : 1; - u32 lcdnoise_test : 1; - u32 keyshort_test : 1; - u32 mux_open_test : 1; -}; - -struct incell_threshold_b { - int short_res_min; - int short_res_vk_min; - int open_cb_min; - int open_k1_check; - int open_k1_value; - int open_k2_check; - int open_k2_value; - int cb_min; - int cb_max; - int cb_vkey_check; - int cb_min_vk; - int cb_max_vk; - int rawdata_min; - int rawdata_max; - int rawdata_vkey_check; - int rawdata_min_vk; - int rawdata_max_vk; - int lcdnoise_frame; - int lcdnoise_coefficient; - int lcdnoise_coefficient_vkey; - int open_nmos; - int keyshort_k1; - int keyshort_cb_max; - int rawdata2_min; - int rawdata2_max; - int mux_open_cb_min; -}; - -struct incell_threshold { - struct incell_threshold_b basic; - int *rawdata_min; - int *rawdata_max; - int *rawdata2_min; - int *rawdata2_max; - int *cb_min; - int *cb_max; -}; - -struct incell_test { - struct incell_threshold thr; - union { - int tmp; - struct incell_testitem item; - } u; -}; - -/* mc_sc */ -enum mapping_type { - MAPPING = 0, - NO_MAPPING = 1, -}; - -struct mc_sc_testitem { - u32 rawdata_test : 1; - u32 rawdata_uniformity_test : 1; - u32 scap_cb_test : 1; - u32 scap_rawdata_test : 1; - u32 short_test : 1; - u32 panel_differ_test : 1; -}; - -struct mc_sc_threshold_b { - int rawdata_h_min; - int rawdata_h_max; - int rawdata_set_hfreq; - int rawdata_l_min; - int rawdata_l_max; - int rawdata_set_lfreq; - int uniformity_check_tx; - int uniformity_check_rx; - int uniformity_check_min_max; - int uniformity_tx_hole; - int uniformity_rx_hole; - int uniformity_min_max_hole; - int scap_cb_off_min; - int scap_cb_off_max; - int scap_cb_wp_off_check; - int scap_cb_on_min; - int scap_cb_on_max; - int scap_cb_wp_on_check; - int scap_rawdata_off_min; - int scap_rawdata_off_max; - int scap_rawdata_wp_off_check; - int scap_rawdata_on_min; - int scap_rawdata_on_max; - int scap_rawdata_wp_on_check; - int short_cg; - int short_cc; - int panel_differ_min; - int panel_differ_max; - -}; - -struct mc_sc_threshold { - struct mc_sc_threshold_b basic; - int *rawdata_h_min; - int *rawdata_h_max; - int *rawdata_l_min; - int *rawdata_l_max; - int *tx_linearity_max; - int *tx_linearity_min; - int *rx_linearity_max; - int *rx_linearity_min; - int *scap_cb_off_min; - int *scap_cb_off_max; - int *scap_cb_on_min; - int *scap_cb_on_max; - int *scap_rawdata_off_min; - int *scap_rawdata_off_max; - int *scap_rawdata_on_min; - int *scap_rawdata_on_max; - int *panel_differ_min; - int *panel_differ_max; -}; - -struct mc_sc_test { - struct mc_sc_threshold thr; - union { - u32 tmp; - struct mc_sc_testitem item; - } u; -}; - -/* sc */ -struct sc_testitem { - u32 rawdata_test : 1; - u32 cb_test : 1; - u32 delta_cb_test : 1; - u32 short_test : 1; -}; - -struct sc_threshold_b { - int rawdata_min; - int rawdata_max; - int cb_min; - int cb_max; - int dcb_base; - int dcb_differ_max; - int dcb_key_check; - int dcb_key_differ_max; - int dcb_ds1; - int dcb_ds2; - int dcb_ds3; - int dcb_ds4; - int dcb_ds5; - int dcb_ds6; - int dcb_critical_check; - int dcb_cs1; - int dcb_cs2; - int dcb_cs3; - int dcb_cs4; - int dcb_cs5; - int dcb_cs6; - int short_min; -}; - -struct sc_threshold { - struct sc_threshold_b basic; - int *rawdata_min; - int *rawdata_max; - int *cb_min; - int *cb_max; - int *dcb_sort; - int *dcb_base; -}; - -struct sc_test { - struct sc_threshold thr; - union { - u32 tmp; - struct sc_testitem item; - } u; -}; - -enum test_hw_type { - IC_HW_INCELL = 1, - IC_HW_MC_SC, - IC_HW_SC, -}; - -enum test_scan_mode { - SCAN_NORMAL = 0, - SCAN_SC, -}; - -struct fts_test_node { - int channel_num; - int tx_num; - int rx_num; - int node_num; - int key_num; -}; - -struct fts_test { - struct fts_ts_data *ts_data; - struct fts_test_node node; - struct fts_test_node sc_node; - u8 fw_ver; - u8 va_touch_thr; - u8 vk_touch_thr; - bool key_support; - bool v3_pattern; - u8 mapping; - u8 normalize; - int test_num; - int *buffer; - int buffer_length; - int *node_valid; - int *node_valid_sc; - int basic_thr_count; - int code1; - int code2; - int offset; - union { - struct incell_test incell; - struct mc_sc_test mc_sc; - struct sc_test sc; - } ic; - - struct test_funcs *func; - struct fts_test_data testdata; - char *testresult; - int testresult_len; - struct ini_data ini; -}; - -struct test_funcs { - u64 ctype[FTX_MAX_COMPATIBLE_TYPE]; - enum test_hw_type hwtype; - int startscan_mode; - int key_num_total; - bool rawdata2_support; - bool force_touch; - int (*param_init)(void); - int (*init)(void); - int (*start_test)(void); -}; - -enum byte_mode { - DATA_ONE_BYTE, - DATA_TWO_BYTE, -}; -/* mc_sc */ -enum normalize_type { - NORMALIZE_OVERALL, - NORMALIZE_AUTO, -}; - -enum wp_type { - WATER_PROOF_OFF = 0, - WATER_PROOF_ON = 1, - WATER_PROOF_ON_TX, - WATER_PROOF_ON_RX, - WATER_PROOF_OFF_TX, - WATER_PROOF_OFF_RX, -}; -/* mc end */ - -/* sc */ -enum factory_mode { - FACTORY_NORMAL, - FACTORY_TESTMODE_1, - FACTORY_TESTMODE_2, -}; - -enum dcb_sort_num { - DCB_SORT_MIN = 1, - DCB_SORT_MAX = 6, -}; - -struct dcb_sort_d { - int ch_num; - int deviation; - int critical; - int min; - int max; -}; -/* sc end */ - -enum csv_itemcode_incell { - CODE_ENTER_FACTORY_MODE = 0, - CODE_RAWDATA_TEST = 7, - CODE_CB_TEST = 12, - CODE_SHORT_TEST = 15, - CODE_OPEN_TEST = 25, - CODE_LCD_NOISE_TEST = 27, - CODE_MUX_OPEN_TEST = 41, -}; - -enum csv_itemcode_mc_sc { - CODE_M_RAWDATA_TEST = 7, - CODE_M_SCAP_CB_TEST = 9, - CODE_M_SCAP_RAWDATA_TEST = 10, - CODE_M_WEAK_SHORT_CIRCUIT_TEST = 15, - CODE_M_RAWDATA_UNIFORMITY_TEST = 16, - CODE_M_PANELDIFFER_TEST = 20, -}; - -enum csv_itemcode_sc { - CODE_S_RAWDATA_TEST = 7, - CODE_S_CB_TEST = 13, - CODE_S_DCB_TEST = 14, -}; - -/***************************************************************************** -* Global variable or extern global variabls/functions -*****************************************************************************/ -#ifdef CONFIG_INPUT_FOCALTECH_0FLASH_MMI_IC_NAME_FT8719 -extern struct test_funcs test_func_ft8719; -#endif -#ifdef CONFIG_INPUT_FOCALTECH_0FLASH_MMI_IC_NAME_FT8756 -extern struct test_funcs test_func_ft8756; -#endif - -extern struct fts_test *fts_ftest; - -void sys_delay(int ms); -int focal_abs(int value); -void print_buffer(int *buffer, int length, int line_num); -int fts_test_read_reg(u8 addr, u8 *val); -int fts_test_write_reg(u8 addr, u8 val); -int fts_test_read(u8 addr, u8 *readbuf, int readlen); -int fts_test_write(u8 addr, u8 *writebuf, int writelen); -int enter_work_mode(void); -int enter_factory_mode(void); -int read_mass_data(u8 addr, int byte_num, int *buf); -int chip_clb(void); -int wait_state_update(u8 retval); -int get_cb_incell(u16 saddr, int byte_num, int *cb_buf); -int short_get_adcdata_incell(u8 retval, u8 ch_num, int byte_num, int *adc_buf); -int start_scan(void); -int get_rawdata(int *data); -int get_cb_sc(int byte_num, int *cb_buf, enum byte_mode mode); -bool compare_data(int *data, int min, int max, int min_vk, int max_vk, bool key); -bool compare_array(int *data, int *min, int *max, bool key); -void show_data(int *data, bool key); -/* mc_sc */ -int mapping_switch(u8 mapping); -bool get_fw_wp(u8 wp_channel_select, enum wp_type water_proof_type); -int get_cb_mc_sc(u8 wp, int byte_num, int *cb_buf, enum byte_mode mode); -int get_rawdata_mc_sc(enum wp_type wp, int *data); -int get_rawdata_mc(u8 fre, u8 fir, int *rawdata); -int short_get_adc_data_mc(u8 retval, int byte_num, int *adc_buf, u8 mode); -bool compare_mc_sc(bool, bool, int *, int *, int *); -void show_data_mc_sc(int *data); -void *fts_malloc(size_t size); -void fts_free_proc(void *p); -void fts_test_save_data(char *name, int code, int *data, int datacnt, - bool mc_sc, bool key, bool result); - -#define fts_malloc_r(p, size) do {\ - if (NULL == p) {\ - p = fts_malloc(size);\ - if (NULL == p) {\ - return -ENOMEM;\ - }\ - }\ -} while(0) - -#define fts_free(p) do {\ - if (p) {\ - fts_free_proc(p);\ - p = NULL;\ - }\ -} while(0) - -#define CSV_SUPPORT 1 -#define TXT_SUPPORT 1 - -#define FTS_TEST_DBG(fmt, args...) do { \ -printk("[FTS_TS][TEST]%s:"fmt"\n", __func__, ##args); \ -} while (0) - -#define FTS_TEST_FUNC_ENTER() do { \ - printk("[FTS_TS][TEST]%s: Enter\n", __func__); \ -} while (0) - -#define FTS_TEST_FUNC_EXIT() do { \ - printk("[FTS_TS][TEST]%s: Exit(%d)\n", __func__, __LINE__); \ -} while (0) - -#define FTS_TEST_INFO(fmt, args...) do { \ - printk(KERN_ERR "[FTS_TS/I][TEST]%s:"fmt"\n", __func__, ##args); \ -} while (0) - -#define FTS_TEST_ERROR(fmt, args...) do { \ - printk(KERN_ERR "[FTS_TS/E][TEST]%s:"fmt"\n", __func__, ##args); \ -} while (0) - -#define FTS_TEST_SAVE_INFO(fmt, args...) do { \ - if (fts_ftest->testresult) { \ - fts_ftest->testresult_len += snprintf( \ - fts_ftest->testresult + fts_ftest->testresult_len, \ - TXT_BUFFER_LEN, \ - fmt, ##args);\ - } \ -} while (0) - -#define FTS_TEST_SAVE_ERR(fmt, args...) do { \ - if (fts_ftest->testresult && (fts_ftest->testresult_len < TXT_BUFFER_LEN)) { \ - fts_ftest->testresult_len += snprintf( \ - fts_ftest->testresult + fts_ftest->testresult_len, \ - TXT_BUFFER_LEN, \ - fmt, ##args);\ - } \ - printk(KERN_ERR "[FTS_TS/E][TEST]%s:"fmt"\n", __func__, ##args);\ -} while (0) -#endif diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/focaltech_test_ini.c b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/focaltech_test_ini.c deleted file mode 100755 index 970c2adb4aec..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/focaltech_test_ini.c +++ /dev/null @@ -1,1329 +0,0 @@ -/************************************************************************ -* Copyright (C) 2012-2019, Focaltech Systems (R)£¬All Rights Reserved. -* -* File Name: focaltech_test_ini.c -* -* Author: Focaltech Driver Team -* -* Created: 2016-08-01 -* -* Abstract: parsing function of INI file -* -************************************************************************/ -#include "focaltech_test.h" - -/***************************************************************************** -* Private constant and macro definitions using #define -*****************************************************************************/ -struct ini_ic_type ic_types[] = { - {"FT5X46", 0x54000002}, - {"FT5X46i", 0x54010002}, - {"FT5526", 0x54020002}, - {"FT3X17", 0x54030002}, - {"FT5436", 0x54040002}, - {"FT3X27", 0x54050002}, - {"FT5526i", 0x54060002}, - {"FT5416", 0x54070002}, - {"FT5426", 0x54080002}, - {"FT5435", 0x54090002}, - {"FT7681", 0x540A0002}, - {"FT7661", 0x540B0002}, - {"FT7511", 0x540C0002}, - {"FT7421", 0x540D0002}, - {"FT7311", 0x54100002}, - {"FT3327DQQ-001", 0x41000082}, - {"FT5446DQS-W01", 0x40000082}, - - {"FT5452", 0x55000081}, - {"FT3518", 0x55010081}, - {"FT3558", 0x55020081}, - {"FT3528", 0x55030081}, - {"FT5536", 0x55040081}, - - {"FT5472", 0x8F000083}, - {"FT5446U", 0x8F010083}, - {"FT5456U", 0x8F020083}, - {"FT3417U", 0x8F030083}, - {"FT5426U", 0x8F040083}, - {"FT3428", 0x8F050083}, - {"FT3437U", 0x8F060083}, - - {"FT5822", 0x58000001}, - {"FT5626", 0x58010001}, - {"FT5726", 0x58020001}, - {"FT5826B", 0x58030001}, - {"FT3617", 0x58040001}, - {"FT3717", 0x58050001}, - {"FT7811", 0x58060001}, - {"FT5826S", 0x58070001}, - {"FT3517U", 0x58090001}, - {"FT3557", 0x580A0001}, - - {"FT6X36", 0x63000003}, - {"FT3X07", 0x63010003}, - {"FT6416", 0x63020003}, - {"FT6336G/U", 0x63030003}, - {"FT7401", 0x63040003}, - {"FT3407U", 0x63050003}, - {"FT6236U", 0x63060003}, - {"FT6436U", 0x63070003}, - - {"FT3267", 0x63080004}, - {"FT3367", 0x63090004}, - - {"FT6216", 0x64000084}, - {"FT7302", 0x64010084}, - {"FT7202", 0x64020084}, - {"FT3308", 0x64030084}, - - {"FT8607", 0x81000009}, - {"FT8716", 0x82000005}, - {"FT8716U", 0x44000005}, - {"FT8716F", 0x8A000005}, - {"FT8613", 0x4500000C}, - - {"FT8736", 0x83000006}, - - {"FT8006M", 0x87000007}, - {"FT8201", 0x87010010}, - {"FT7250", 0x87020007}, - - {"FT8006U", 0x8900000B}, - {"FT8006S", 0x8901000B}, - - {"FT8719", 0x8E00000D}, - {"FT8615", 0x9100000F}, - - {"FT8739", 0x8D00000E}, - - {"FT8006P", 0x93000011}, - - {"FT7251", 0x8C000012}, - {"FT7252", 0x92000013}, - - {"FT8613S", 0x94000014}, - - {"FT8756", 0x95000015}, - {"FT8656", 0x95010018}, - - {"FT8302", 0x97000016}, - - {"FT8009", 0x98000017}, - - {"FT3068", 0x65010085}, - {"FT3168", 0x65020085}, - {"FT3067", 0x65030085}, - {"FT3268", 0x65040085}, - {"FT6346U", 0x65050085}, - {"FT6346G", 0x65060085}, -}; - -/***************************************************************************** -* Global variable or extern global variabls/functions -*****************************************************************************/ - -/***************************************************************************** -* Static function prototypes -*****************************************************************************/ -/* Works only for digits and letters, but small and fast */ -#define TOLOWER(x) ((x) | 0x20) -static int fts_strncmp(const char *cs, const char *ct, int count) -{ - u8 c1 = 0, c2 = 0; - - while (count) { - if ((cs == '\0') || (ct == '\0')) - return -1; - c1 = TOLOWER(*cs++); - c2 = TOLOWER(*ct++); - if (c1 != c2) - return c1 < c2 ? -1 : 1; - if (!c1) - break; - count--; - } - - return 0; -} - -static int isspace(int x) -{ - if (x == ' ' || x == '\t' || x == '\n' || x == '\f' || x == '\b' || x == '\r') - return 1; - else - return 0; -} - -static int isdigit(int x) -{ - if (x <= '9' && x >= '0') - return 1; - else - return 0; -} - -static long fts_atol(char *nptr) -{ - int c; /* current char */ - long total; /* current total */ - int sign; /* if ''-'', then negative, otherwise positive */ - /* skip whitespace */ - while ( isspace((int)(unsigned char)*nptr) ) - ++nptr; - c = (int)(unsigned char) * nptr++; - sign = c; /* save sign indication */ - if (c == '-' || c == '+') - c = (int)(unsigned char) * nptr++; /* skip sign */ - total = 0; - while (isdigit(c)) { - total = 10 * total + (c - '0'); /* accumulate digit */ - c = (int)(unsigned char) * nptr++; /* get next char */ - } - if (sign == '-') - return -total; - else - return total; /* return result, negated if necessary */ -} - -static int fts_atoi(char *nptr) -{ - return (int)fts_atol(nptr); -} - -static int fts_test_get_ini_size(char *config_name) -{ - struct file *pfile = NULL; - struct inode *inode = NULL; - off_t fsize = 0; - char filepath[128]; - - FTS_TEST_FUNC_ENTER(); - - memset(filepath, 0, sizeof(filepath)); - sprintf(filepath, "%s%s", FTS_INI_FILE_PATH, config_name); - - if (NULL == pfile) - pfile = filp_open(filepath, O_RDONLY, 0); - if (IS_ERR(pfile)) { - FTS_TEST_ERROR("error occured while opening file %s.", filepath); - return -EIO; - } - -#if 1 - inode = pfile->f_inode; -#else - /* reserved for linux earlier verion */ - inode = pfile->f_dentry->d_inode; -#endif - fsize = inode->i_size; - filp_close(pfile, NULL); - - FTS_TEST_FUNC_ENTER(); - - return fsize; -} - -static int fts_test_read_ini_data(char *config_name, char *config_buf) -{ - struct file *pfile = NULL; - struct inode *inode = NULL; - off_t fsize = 0; - char filepath[128]; - loff_t pos = 0; - mm_segment_t old_fs; - - FTS_TEST_FUNC_ENTER(); - - memset(filepath, 0, sizeof(filepath)); - sprintf(filepath, "%s%s", FTS_INI_FILE_PATH, config_name); - if (NULL == pfile) { - pfile = filp_open(filepath, O_RDONLY, 0); - } - if (IS_ERR(pfile)) { - FTS_TEST_ERROR("error occured while opening file %s.", filepath); - return -EIO; - } - -#if 1 - inode = pfile->f_inode; -#else - /* reserved for linux earlier verion */ - inode = pfile->f_dentry->d_inode; -#endif - fsize = inode->i_size; - old_fs = get_fs(); - set_fs(KERNEL_DS); - pos = 0; - vfs_read(pfile, config_buf, fsize, &pos); - filp_close(pfile, NULL); - set_fs(old_fs); - - FTS_TEST_FUNC_EXIT(); - return 0; -} - -static int fts_test_get_ini_default(struct ini_data *ini, char *fwname) -{ - int ret = 0; - int inisize = 0; - - inisize = fts_test_get_ini_size(fwname); - FTS_TEST_DBG("ini file size:%d", inisize); - if (inisize <= 0) { - FTS_TEST_ERROR("get ini file size fail"); - return -ENODATA; - } - - ini->data = vmalloc(inisize + 1); - if (NULL == ini->data) { - FTS_TEST_ERROR("malloc memory for ini data fail"); - return -ENOMEM; - } - memset(ini->data, 0, inisize + 1); - ini->length = inisize + 1; - - ret = fts_test_read_ini_data(fwname, ini->data); - if (ret) { - FTS_TEST_ERROR("read ini file fail"); - return -ENODATA; - } - ini->data[inisize] = '\n'; /* last line is null line */ - - return 0; -} - -static int fts_test_get_ini_via_request_firmware(struct ini_data *ini, char *fwname) -{ - int ret = 0; - const struct firmware *fw = NULL; - struct device *dev = &fts_data->input_dev->dev; - - ret = request_firmware(&fw, fwname, dev); - if (0 == ret) { - FTS_TEST_INFO("firmware request(%s) success", fwname); - ini->data = vmalloc(fw->size + 1); - if (NULL == ini->data) { - FTS_TEST_ERROR("ini->data buffer vmalloc fail"); - ret = -ENOMEM; - } else { - memcpy(ini->data, fw->data, fw->size); - ini->data[fw->size] = '\n'; - ini->length = fw->size + 1; - } - } else { - FTS_TEST_INFO("firmware request(%s) fail,ret=%d", fwname, ret); - } - - if (fw != NULL) { - release_firmware(fw); - fw = NULL; - } - - return ret; -} - - -static void str_space_remove(char *str) -{ - char *t = str; - char *s = str; - - while (*t != '\0') { - if (*t != ' ') { - *s = *t; - s++; - } - t++; - } - - *s = '\0'; -} - -static void print_ini_data(struct ini_data *ini) -{ - int i = 0; - int j = 0; - struct ini_section *section = NULL; - struct ini_keyword *keyword = NULL; - struct fts_test *tdata = fts_ftest; - - if (tdata && tdata->ts_data && (tdata->ts_data->log_level < 10)) { - return; - } - - if (!ini || !ini->tmp) { - FTS_TEST_DBG("ini is null"); - return; - } - - FTS_TEST_DBG("section num:%d, keyword num total:%d", - ini->section_num, ini->keyword_num_total); - for (i = 0; i < ini->section_num; i++) { - section = &ini->section[i]; - FTS_TEST_DBG("section name:[%s] keyword num:%d", - section->name, section->keyword_num); - for (j = 0; j < section->keyword_num; j++) { - keyword = §ion->keyword[j]; - FTS_TEST_DBG("%s=%s", keyword->name, keyword->value); - } - } -} - -static int ini_get_line(char *filedata, char *line_data, int *line_len) -{ - int i = 0; - int line_length = 0; - int type; - - /* get a line data */ - for (i = 0; i < MAX_INI_LINE_LEN; i++) { - if (('\n' == filedata[i]) || ('\r' == filedata[i])) { - line_data[line_length++] = '\0'; - if (('\n' == filedata[i + 1]) || ('\r' == filedata[i + 1])) { - line_length++; - } - break; - } else { - line_data[line_length++] = filedata[i]; - } - } - - if (i >= MAX_INI_LINE_LEN) { - FTS_TEST_ERROR("line length(%d)>max(%d)", line_length, MAX_INI_LINE_LEN); - return -ENODATA; - } - - /* remove space */ - str_space_remove(line_data); - - /* confirm line type */ - if (('\0' == line_data[0]) || ('#' == line_data[0])) { - type = LINE_OTHER; - } else if ('[' == line_data[0]) { - type = LINE_SECTION; - } else { - type = LINE_KEYWORD; /* key word */ - } - - *line_len = line_length; - return type; -} - -static int ini_parse_keyword(struct ini_data *ini, char *line_buffer) -{ - int i = 0; - int offset = 0; - int length = strlen(line_buffer); - struct ini_section *section = NULL; - - for (i = 0; i < length; i++) { - if (line_buffer[i] == '=') - break; - } - - if ((i == 0) || (i >= length)) { - FTS_TEST_ERROR("mark(=)in keyword line fail"); - return -ENODATA; - } - - if ((ini->section_num > 0) && (ini->section_num < MAX_INI_SECTION_NUM)) { - section = &ini->section[ini->section_num - 1]; - } - - if (NULL == section) { - FTS_TEST_ERROR("section is null"); - return -ENODATA; - } - - offset = ini->keyword_num_total; - if (offset > MAX_KEYWORD_NUM) { - FTS_TEST_ERROR("keyword num(%d)>max(%d),please check MAX_KEYWORD_NUM", - ini->keyword_num_total, MAX_KEYWORD_NUM); - return -ENODATA; - } - memcpy(ini->tmp[offset].name, &line_buffer[0], i); - ini->tmp[offset].name[i] = '\0'; - memcpy(ini->tmp[offset].value, &line_buffer[i + 1], length - i - 1); - ini->tmp[offset].value[length - i - 1] = '\0'; - section->keyword_num++; - ini->keyword_num_total++; - - return 0; -} - -static int ini_parse_section(struct ini_data *ini, char *line_buffer) -{ - int length = strlen(line_buffer); - struct ini_section *section = NULL; - - if ((length <= 2) || (length > MAX_KEYWORD_NAME_LEN)) { - FTS_TEST_ERROR("section line length fail"); - return -EINVAL; - } - - if ((ini->section_num < 0) || (ini->section_num >= MAX_INI_SECTION_NUM)) { - FTS_TEST_ERROR("section_num(%d) fail", ini->section_num); - return -EINVAL; - } - section = &ini->section[ini->section_num]; - memcpy(section->name, line_buffer + 1, length - 2); - section->name[length - 2] = '\0'; - FTS_TEST_INFO("section:%s, keyword offset:%d", - section->name, ini->keyword_num_total); - section->keyword = (struct ini_keyword *)&ini->tmp[ini->keyword_num_total]; - section->keyword_num = 0; - ini->section_num++; - if (ini->section_num > MAX_INI_SECTION_NUM) { - FTS_TEST_ERROR("section num(%d)>max(%d), please check MAX_INI_SECTION_NUM", - ini->section_num, MAX_INI_SECTION_NUM); - return -ENOMEM; - } - - return 0; -} - -static int ini_init_inidata(struct ini_data *ini) -{ - int pos = 0; - int ret = 0; - char line_buffer[MAX_INI_LINE_LEN] = { 0 }; - int line_len = 0; - - if (!ini || !ini->data || !ini->tmp) { - FTS_TEST_DBG("ini/data/tmp is null"); - return -EINVAL; - } - - while (pos < ini->length) { - ret = ini_get_line(ini->data + pos, line_buffer, &line_len); - if (ret < 0) { - FTS_TEST_ERROR("ini_get_line fail"); - return ret; - } else if (ret == LINE_KEYWORD) { - ret = ini_parse_keyword(ini, line_buffer); - if (ret < 0) { - FTS_TEST_ERROR("ini_parse_keyword fail"); - return ret; - } - } else if (ret == LINE_SECTION) { - ret = ini_parse_section(ini, line_buffer); - if (ret < 0) { - FTS_TEST_ERROR("ini_parse_section fail"); - return ret; - } - } - - pos += line_len; - } - - print_ini_data(ini); - return 0; -} - -static int ini_get_key(char *section_name, char *key_name, char *value) -{ - int i = 0; - int j = 0; - struct ini_data *ini = &fts_ftest->ini; - struct ini_section *section; - struct ini_keyword *keyword; - int key_len = 0; - int log_level = fts_ftest->ts_data->log_level; - - if (log_level >= 10) { - FTS_TEST_DBG("section name:%s, key name:%s", section_name, key_name); - FTS_TEST_DBG("section num:%d", ini->section_num); - } - - for (i = 0; i < ini->section_num; i++) { - section = &ini->section[i]; - key_len = strlen(section_name); - if (key_len != strlen(section->name)) - continue; - if (fts_strncmp(section->name, section_name, key_len) != 0) - continue; - - if (log_level >= 10) { - FTS_TEST_DBG("section name:%s keyword num:%d", - section->name, section->keyword_num); - } - for (j = 0; j < section->keyword_num; j++) { - keyword = §ion->keyword[j]; - key_len = strlen(key_name); - if (key_len == strlen(keyword->name)) { - if (0 == fts_strncmp(keyword->name, key_name, key_len)) { - key_len = strlen(keyword->value); - memcpy(value, keyword->value, key_len); - if (log_level >= 3) { - FTS_TEST_DBG("section:%s,%s=%s", - section_name, key_name, value); - } - - return key_len; - } - } - } - } - - return -ENODATA; -} - -/* return keyword's value length if success */ -static int ini_get_string_value(char *section_name, char *key_name, char *rval) -{ - if (!section_name || !key_name || !rval) { - FTS_TEST_ERROR("section_name/key_name/rval is null"); - return -EINVAL; - } - - return ini_get_key(section_name, key_name, rval); -} - -int get_keyword_value(char *section, char *name, int *value) -{ - int ret = 0; - char str[MAX_KEYWORD_VALUE_LEN] = { 0 }; - - ret = ini_get_string_value(section, name, str); - if (ret > 0) { - /* search successfully, so change value, otherwise keep default */ - *value = fts_atoi(str); - } - - return ret; -} - -static void fts_init_buffer(int *buffer, int value, int len, bool key_check, int key_value, int key_len) -{ - int i = 0; - int va_len = 0; - - if (NULL == buffer) { - FTS_TEST_ERROR("buffer is null\n"); - return; - } - - va_len = len - key_len; - if (va_len < 0) { - FTS_TEST_ERROR("total len(0x%x) less key len(0x%x)\n", len, key_len); - return; - } - - for (i = 0; i < len; i++) { - buffer[i] = value; - } - - if (key_check) { - for (i = 0; i < key_len; i++) { - buffer[va_len + i] = key_value; - } - } - -} - -static int get_test_item(char name[][MAX_KEYWORD_NAME_LEN], int length, int *val) -{ - int i = 0; - int ret = 0; - int tmpval = 0; - - if (length > TEST_ITEM_COUNT_MAX) { - FTS_TEST_SAVE_ERR("test item count(%d) > max(%d)\n", - length, TEST_ITEM_COUNT_MAX); - return -EINVAL; - } - - FTS_TEST_INFO("test items in total of driver:%d", length); - *val = 0; - for (i = 0; i < length; i++) { - tmpval = 0; - ret = get_value_testitem(name[i], &tmpval); - if (ret < 0) { - FTS_TEST_DBG("test item:%s not found", name[i]); - } else { - FTS_TEST_DBG("test item:%s=%d", name[i], tmpval); - *val |= (tmpval << i); - } - } - - return 0; -} - -static int get_basic_threshold(char name[][MAX_KEYWORD_NAME_LEN], int length, int *val) -{ - int i = 0; - int ret = 0; - struct fts_test *tdata = fts_ftest; - int log_level = tdata->ts_data->log_level; - - FTS_TEST_INFO("basic_thr string length(%d), count(%d)\n", length, tdata->basic_thr_count); - if (length > fts_ftest->basic_thr_count) { - FTS_TEST_SAVE_ERR("basic_thr string length > count\n"); - return -EINVAL; - } - - for (i = 0; i < length; i++) { - ret = get_value_basic(name[i], &val[i]); - if (log_level >= 3) { - if (ret < 0) { - FTS_TEST_DBG("basic thr:%s not found", name[i]); - } else { - FTS_TEST_DBG("basic thr:%s=%d", name[i], val[i]); - } - } - } - - return 0; -} - -static void get_detail_threshold(char *key_name, bool is_prex, int *thr) -{ - char str[MAX_KEYWORD_VALUE_LEN] = { 0 }; - char str_temp[MAX_KEYWORD_NAME_LEN] = { 0 }; - char str_tmp[MAX_KEYWORD_VALUE_ONE_LEN] = { 0 }; - struct fts_test *tdata = fts_ftest; - int divider_pos = 0; - int index = 0; - int i = 0; - int j = 0; - int k = 0; - int tx_num = 0; - int rx_num = 0; - - if (!key_name || !thr) { - FTS_TEST_ERROR("key_name/thr is null"); - return; - } - - if (is_prex) { - tx_num = tdata->node.tx_num; - rx_num = tdata->node.rx_num; - } - for (i = 0; i < tx_num + 1; i++) { - if (is_prex) { - snprintf(str_temp, MAX_KEYWORD_NAME_LEN, "%s%d", key_name, (i + 1)); - } else { - snprintf(str_temp, MAX_KEYWORD_NAME_LEN, "%s", key_name); - } - divider_pos = ini_get_string_value("SpecialSet", str_temp, str); - if (divider_pos <= 0) - continue; - index = 0; - k = 0; - memset(str_tmp, 0, sizeof(str_tmp)); - for (j = 0; j < divider_pos; j++) { - if (',' == str[j]) { - thr[i * rx_num + k] = (short)(fts_atoi(str_tmp)); - index = 0; - memset(str_tmp, 0x00, sizeof(str_tmp)); - k++; - } else { - if (' ' == str[j]) - continue; - str_tmp[index] = str[j]; - index++; - } - } - } -} - -static int init_node_valid(void) -{ - char str[MAX_KEYWORD_NAME_LEN] = {0}; - int i = 0; - int j = 0; - int chy = 0; - int node_num = 0; - int cnt = 0; - struct fts_test *tdata = fts_ftest; - - if (!tdata || !tdata->node_valid || !tdata->node_valid_sc) { - FTS_TEST_ERROR("tdata/node_valid/node_valid_sc is null"); - return -EINVAL; - } - - chy = tdata->node.rx_num; - node_num = tdata->node.node_num; - fts_init_buffer(tdata->node_valid, 1 , node_num, false, 0, 0); - if ((tdata->func->hwtype == IC_HW_INCELL) || (tdata->func->hwtype == IC_HW_MC_SC)) { - for (cnt = 0; cnt < node_num; cnt++) { - i = cnt / chy + 1; - j = cnt % chy + 1; - snprintf(str, MAX_KEYWORD_NAME_LEN, "InvalidNode[%d][%d]", i, j); - get_keyword_value("INVALID_NODE", str, &tdata->node_valid[cnt]); - } - } - - if (tdata->func->hwtype == IC_HW_MC_SC) { - chy = tdata->sc_node.rx_num; - node_num = tdata->sc_node.node_num; - fts_init_buffer(tdata->node_valid_sc, 1, node_num, false, 0, 0); - - for (cnt = 0; cnt < node_num; cnt++) { - i = (cnt >= chy) ? 2 : 1; - j = (cnt >= chy) ? (cnt - chy + 1) : (cnt + 1); - snprintf(str, MAX_KEYWORD_NAME_LEN, "InvalidNodeS[%d][%d]", i, j); - get_keyword_value("INVALID_NODES", str, &tdata->node_valid_sc[cnt]); - } - } - - print_buffer(tdata->node_valid, tdata->node.node_num, tdata->node.rx_num); - print_buffer(tdata->node_valid_sc, tdata->sc_node.node_num, tdata->sc_node.rx_num); - return 0; -} - -/* incell */ -static int get_test_item_incell(void) -{ - int ret = 0; - char item_name[][MAX_KEYWORD_NAME_LEN] = TEST_ITEM_INCELL; - int length = sizeof(item_name) / MAX_KEYWORD_NAME_LEN; - int item_val = 0; - - ret = get_test_item(item_name, length, &item_val); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get test item fail\n"); - return ret; - } - - fts_ftest->ic.incell.u.tmp = item_val; - return 0; -} - -static char bthr_name_incell[][MAX_KEYWORD_NAME_LEN] = BASIC_THRESHOLD_INCELL; -static int get_test_threshold_incell(void) -{ - int ret = 0; - int length = sizeof(bthr_name_incell) / MAX_KEYWORD_NAME_LEN; - struct fts_test *tdata = fts_ftest; - struct incell_threshold *thr = &tdata->ic.incell.thr; - int node_num = tdata->node.node_num; - int key_num = tdata->node.key_num; - bool raw_key_check = thr->basic.rawdata_vkey_check; - bool cb_key_check = thr->basic.cb_vkey_check; - - tdata->basic_thr_count = sizeof(struct incell_threshold_b) / sizeof(int); - /* get standard basic threshold */ - ret = get_basic_threshold(bthr_name_incell, length, (int *)&thr->basic); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get basic thr fail\n"); - return ret; - } - - /* basic special set by ic */ - if (tdata->func->param_init) { - ret = tdata->func->param_init(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("special basic thr init fail\n"); - return ret; - } - } - - /* init buffer */ - fts_init_buffer(thr->rawdata_max, thr->basic.rawdata_max, node_num, raw_key_check, thr->basic.rawdata_max_vk, key_num); - fts_init_buffer(thr->rawdata_min, thr->basic.rawdata_min, node_num, raw_key_check, thr->basic.rawdata_min_vk, key_num); - if (tdata->func->rawdata2_support) { - fts_init_buffer(thr->rawdata2_max, thr->basic.rawdata2_max, node_num, false, 0, 0); - fts_init_buffer(thr->rawdata2_min, thr->basic.rawdata2_min, node_num, false, 0, 0); - } - fts_init_buffer(thr->cb_max, thr->basic.cb_max, node_num, cb_key_check, thr->basic.cb_max_vk, key_num); - fts_init_buffer(thr->cb_min, thr->basic.cb_min, node_num, cb_key_check, thr->basic.cb_min_vk, key_num); - - /* detail threshold */ - get_detail_threshold("RawData_Max_Tx", true, thr->rawdata_max); - get_detail_threshold("RawData_Min_Tx", true, thr->rawdata_min); - get_detail_threshold("CB_Max_Tx", true, thr->cb_max); - get_detail_threshold("CB_Min_Tx", true, thr->cb_min); - - return 0; -} - -static void print_thr_incell(void) -{ - struct fts_test *tdata = fts_ftest; - struct incell_threshold *thr = &tdata->ic.incell.thr; - - if (tdata->ts_data->log_level < 3) { - return; - } - - FTS_TEST_DBG("short_res_min:%d", thr->basic.short_res_min); - FTS_TEST_DBG("short_res_vk_min:%d", thr->basic.short_res_vk_min); - FTS_TEST_DBG("open_cb_min:%d", thr->basic.open_cb_min); - FTS_TEST_DBG("open_k1_check:%d", thr->basic.open_k1_check); - FTS_TEST_DBG("open_k1_value:%d", thr->basic.open_k1_value); - FTS_TEST_DBG("open_k2_check:%d", thr->basic.open_k2_check); - FTS_TEST_DBG("open_k2_value:%d", thr->basic.open_k2_value); - FTS_TEST_DBG("cb_min:%d", thr->basic.cb_min); - FTS_TEST_DBG("cb_max:%d", thr->basic.cb_max); - FTS_TEST_DBG("cb_vkey_check:%d", thr->basic.cb_vkey_check); - FTS_TEST_DBG("cb_min_vk:%d", thr->basic.cb_min_vk); - FTS_TEST_DBG("cb_max_vk:%d", thr->basic.cb_max_vk); - FTS_TEST_DBG("rawdata_min:%d", thr->basic.rawdata_min); - FTS_TEST_DBG("rawdata_max:%d", thr->basic.rawdata_max); - FTS_TEST_DBG("rawdata_vkey_check:%d", thr->basic.rawdata_vkey_check); - FTS_TEST_DBG("rawdata_min_vk:%d", thr->basic.rawdata_min_vk); - FTS_TEST_DBG("rawdata_max_vk:%d", thr->basic.rawdata_max_vk); - FTS_TEST_DBG("lcdnoise_frame:%d", thr->basic.lcdnoise_frame); - FTS_TEST_DBG("lcdnoise_coefficient:%d", thr->basic.lcdnoise_coefficient); - FTS_TEST_DBG("lcdnoise_coefficient_vkey:%d", thr->basic.lcdnoise_coefficient_vkey); - - FTS_TEST_DBG("open_nmos:%d", thr->basic.open_nmos); - FTS_TEST_DBG("keyshort_k1:%d", thr->basic.keyshort_k1); - FTS_TEST_DBG("keyshort_cb_max:%d", thr->basic.keyshort_cb_max); - FTS_TEST_DBG("rawdata2_min:%d", thr->basic.rawdata2_min); - FTS_TEST_DBG("rawdata2_max:%d", thr->basic.rawdata2_max); - - - print_buffer(thr->rawdata_min, tdata->node.node_num, tdata->node.rx_num); - print_buffer(thr->rawdata_max, tdata->node.node_num, tdata->node.rx_num); - print_buffer(thr->cb_min, tdata->node.node_num, tdata->node.rx_num); - print_buffer(thr->cb_max, tdata->node.node_num, tdata->node.rx_num); - print_buffer(thr->rawdata2_min, tdata->node.node_num, tdata->node.rx_num); - print_buffer(thr->rawdata2_max, tdata->node.node_num, tdata->node.rx_num); -} - -static int ini_init_test_incell(void) -{ - int ret = 0; - - ret = get_test_item_incell(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get incell test item fail\n"); - return ret; - } - - - ret = get_test_threshold_incell(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get incell threshold fail\n"); - return ret; - } - - print_thr_incell(); - return 0; -} - -/* mc_sc */ -static int get_test_item_mc_sc(void) -{ - int ret = 0; - char item_name[][MAX_KEYWORD_NAME_LEN] = TEST_ITEM_MC_SC; - int length = sizeof(item_name) / MAX_KEYWORD_NAME_LEN; - int item_val = 0; - - ret = get_test_item(item_name, length, &item_val); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get test item fail\n"); - return ret; - } - - fts_ftest->ic.mc_sc.u.tmp = item_val; - FTS_TEST_INFO("test item:0x%x in ini", fts_ftest->ic.mc_sc.u.tmp); - return 0; -} - -static char bthr_name_mc_sc[][MAX_KEYWORD_NAME_LEN] = BASIC_THRESHOLD_MC_SC; -static int get_test_threshold_mc_sc(void) -{ - int ret = 0; - int length = sizeof(bthr_name_mc_sc) / MAX_KEYWORD_NAME_LEN; - struct fts_test *tdata = fts_ftest; - struct mc_sc_threshold *thr = &tdata->ic.mc_sc.thr; - int node_num = tdata->node.node_num; - int sc_num = tdata->sc_node.node_num; - - tdata->basic_thr_count = sizeof(struct mc_sc_threshold_b) / sizeof(int); - /* get standard basic threshold */ - ret = get_basic_threshold(bthr_name_mc_sc, length, (int *)&thr->basic); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get basic thr fail\n"); - return ret; - } - - /* basic special set by ic */ - if (tdata->func->param_init) { - ret = tdata->func->param_init(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("special basic thr init fail\n"); - return ret; - } - } - - /* init buffer */ - fts_init_buffer(thr->rawdata_h_min, thr->basic.rawdata_h_min, node_num, false, 0, 0); - fts_init_buffer(thr->rawdata_h_max, thr->basic.rawdata_h_max, node_num, false, 0, 0); - if (tdata->func->rawdata2_support) { - fts_init_buffer(thr->rawdata_l_min, thr->basic.rawdata_l_min, node_num, false, 0, 0); - fts_init_buffer(thr->rawdata_l_max, thr->basic.rawdata_l_max, node_num, false, 0, 0); - } - fts_init_buffer(thr->tx_linearity_max, thr->basic.uniformity_tx_hole, node_num, false, 0, 0); - fts_init_buffer(thr->tx_linearity_min, 0, node_num, false, 0, 0); - fts_init_buffer(thr->rx_linearity_max, thr->basic.uniformity_rx_hole, node_num, false, 0, 0); - fts_init_buffer(thr->rx_linearity_min, 0, node_num, false, 0, 0); - fts_init_buffer(thr->scap_cb_off_min, thr->basic.scap_cb_off_min, sc_num, false, 0, 0); - fts_init_buffer(thr->scap_cb_off_max, thr->basic.scap_cb_off_max, sc_num, false, 0, 0); - fts_init_buffer(thr->scap_cb_on_min, thr->basic.scap_cb_on_min, sc_num, false, 0, 0); - fts_init_buffer(thr->scap_cb_on_max, thr->basic.scap_cb_on_max, sc_num, false, 0, 0); - fts_init_buffer(thr->scap_rawdata_off_min, thr->basic.scap_rawdata_off_min, sc_num, false, 0, 0); - fts_init_buffer(thr->scap_rawdata_off_max, thr->basic.scap_rawdata_off_max, sc_num, false, 0, 0); - fts_init_buffer(thr->scap_rawdata_on_min, thr->basic.scap_rawdata_on_min, sc_num, false, 0, 0); - fts_init_buffer(thr->scap_rawdata_on_max, thr->basic.scap_rawdata_on_max, sc_num, false, 0, 0); - fts_init_buffer(thr->panel_differ_min, thr->basic.panel_differ_min, node_num, false, 0, 0); - fts_init_buffer(thr->panel_differ_max, thr->basic.panel_differ_max, node_num, false, 0, 0); - - /* detail threshold */ - get_detail_threshold("RawData_Min_High_Tx", true, thr->rawdata_h_min); - get_detail_threshold("RawData_Max_High_Tx", true, thr->rawdata_h_max); - if (tdata->func->rawdata2_support) { - get_detail_threshold("RawData_Min_Low_Tx", true, thr->rawdata_l_min); - get_detail_threshold("RawData_Max_Low_Tx", true, thr->rawdata_l_max); - } - get_detail_threshold("Tx_Linearity_Max_Tx", true, thr->tx_linearity_max); - get_detail_threshold("Rx_Linearity_Max_Tx", true, thr->rx_linearity_max); - get_detail_threshold("ScapCB_OFF_Min_", true, thr->scap_cb_off_min); - get_detail_threshold("ScapCB_OFF_Max_", true, thr->scap_cb_off_max); - get_detail_threshold("ScapCB_ON_Min_", true, thr->scap_cb_on_min); - get_detail_threshold("ScapCB_ON_Max_", true, thr->scap_cb_on_max); - get_detail_threshold("ScapRawData_OFF_Min_", true, thr->scap_rawdata_off_min); - get_detail_threshold("ScapRawData_OFF_Max_", true, thr->scap_rawdata_off_max); - get_detail_threshold("ScapRawData_ON_Min_", true, thr->scap_rawdata_on_min); - get_detail_threshold("ScapRawData_ON_Max_", true, thr->scap_rawdata_on_max); - get_detail_threshold("Panel_Differ_Min_Tx", true, thr->panel_differ_min); - get_detail_threshold("Panel_Differ_Max_Tx", true, thr->panel_differ_max); - - return 0; -} - -static void print_thr_mc_sc(void) -{ - struct fts_test *tdata = fts_ftest; - struct mc_sc_threshold *thr = &tdata->ic.mc_sc.thr; - - if (tdata->ts_data->log_level < 3) { - return; - } - - FTS_TEST_DBG("rawdata_h_min:%d", thr->basic.rawdata_h_min); - FTS_TEST_DBG("rawdata_h_max:%d", thr->basic.rawdata_h_max); - FTS_TEST_DBG("rawdata_set_hfreq:%d", thr->basic.rawdata_set_hfreq); - FTS_TEST_DBG("rawdata_l_min:%d", thr->basic.rawdata_l_min); - FTS_TEST_DBG("rawdata_l_max:%d", thr->basic.rawdata_l_max); - FTS_TEST_DBG("rawdata_set_lfreq:%d", thr->basic.rawdata_set_lfreq); - FTS_TEST_DBG("uniformity_check_tx:%d", thr->basic.uniformity_check_tx); - FTS_TEST_DBG("uniformity_check_rx:%d", thr->basic.uniformity_check_rx); - FTS_TEST_DBG("uniformity_check_min_max:%d", thr->basic.uniformity_check_min_max); - FTS_TEST_DBG("uniformity_tx_hole:%d", thr->basic.uniformity_tx_hole); - FTS_TEST_DBG("uniformity_rx_hole:%d", thr->basic.uniformity_rx_hole); - FTS_TEST_DBG("uniformity_min_max_hole:%d", thr->basic.uniformity_min_max_hole); - FTS_TEST_DBG("scap_cb_off_min:%d", thr->basic.scap_cb_off_min); - FTS_TEST_DBG("scap_cb_off_max:%d", thr->basic.scap_cb_off_max); - FTS_TEST_DBG("scap_cb_wp_off_check:%d", thr->basic.scap_cb_wp_off_check); - FTS_TEST_DBG("scap_cb_on_min:%d", thr->basic.scap_cb_on_min); - FTS_TEST_DBG("scap_cb_on_max:%d", thr->basic.scap_cb_on_max); - FTS_TEST_DBG("scap_cb_wp_on_check:%d", thr->basic.scap_cb_wp_on_check); - FTS_TEST_DBG("scap_rawdata_off_min:%d", thr->basic.scap_rawdata_off_min); - FTS_TEST_DBG("scap_rawdata_off_max:%d", thr->basic.scap_rawdata_off_max); - FTS_TEST_DBG("scap_rawdata_wp_off_check:%d", thr->basic.scap_rawdata_wp_off_check); - FTS_TEST_DBG("scap_rawdata_on_min:%d", thr->basic.scap_rawdata_on_min); - FTS_TEST_DBG("scap_rawdata_on_max:%d", thr->basic.scap_rawdata_on_max); - FTS_TEST_DBG("scap_rawdata_wp_on_check:%d", thr->basic.scap_rawdata_wp_on_check); - FTS_TEST_DBG("short_cg:%d", thr->basic.short_cg); - FTS_TEST_DBG("short_cc:%d", thr->basic.short_cc); - FTS_TEST_DBG("panel_differ_min:%d", thr->basic.panel_differ_min); - FTS_TEST_DBG("panel_differ_max:%d", thr->basic.panel_differ_max); - - print_buffer(thr->rawdata_h_min, tdata->node.node_num, tdata->node.rx_num); - print_buffer(thr->rawdata_h_max, tdata->node.node_num, tdata->node.rx_num); - print_buffer(thr->rawdata_l_min, tdata->node.node_num, tdata->node.rx_num); - print_buffer(thr->rawdata_l_max, tdata->node.node_num, tdata->node.rx_num); - print_buffer(thr->scap_cb_off_min, tdata->sc_node.node_num, tdata->sc_node.rx_num); - print_buffer(thr->scap_cb_off_max, tdata->sc_node.node_num, tdata->sc_node.rx_num); - print_buffer(thr->scap_cb_on_min, tdata->sc_node.node_num, tdata->sc_node.rx_num); - print_buffer(thr->scap_cb_on_max, tdata->sc_node.node_num, tdata->sc_node.rx_num); - print_buffer(thr->scap_rawdata_off_min, tdata->sc_node.node_num, tdata->sc_node.rx_num); - print_buffer(thr->scap_rawdata_off_max, tdata->sc_node.node_num, tdata->sc_node.rx_num); - print_buffer(thr->scap_rawdata_on_min, tdata->sc_node.node_num, tdata->sc_node.rx_num); - print_buffer(thr->scap_rawdata_on_max, tdata->sc_node.node_num, tdata->sc_node.rx_num); - print_buffer(thr->panel_differ_min, tdata->node.node_num, tdata->node.rx_num); - print_buffer(thr->panel_differ_max, tdata->node.node_num, tdata->node.rx_num); -} - -static int ini_init_test_mc_sc(void) -{ - int ret = 0; - - ret = get_test_item_mc_sc(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get mc_sc test item fail\n"); - return ret; - } - - ret = get_test_threshold_mc_sc(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get mc_sc threshold fail\n"); - return ret; - } - - print_thr_mc_sc(); - return 0; -} - -/* sc */ -static int get_test_item_sc(void) -{ - int ret = 0; - char item_name[][MAX_KEYWORD_NAME_LEN] = TEST_ITEM_SC; - int length = sizeof(item_name) / MAX_KEYWORD_NAME_LEN; - int item_val = 0; - - ret = get_test_item(item_name, length, &item_val); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get test item fail\n"); - return ret; - } - - fts_ftest->ic.sc.u.tmp = item_val; - return 0; -} - -static char bthr_name_sc[][MAX_KEYWORD_NAME_LEN] = BASIC_THRESHOLD_SC; -static int get_test_threshold_sc(void) -{ - int ret = 0; - int length = sizeof(bthr_name_sc) / MAX_KEYWORD_NAME_LEN; - struct fts_test *tdata = fts_ftest; - struct sc_threshold *thr = &tdata->ic.sc.thr; - int node_num = tdata->node.node_num; - - tdata->basic_thr_count = sizeof(struct sc_threshold_b) / sizeof(int); - /* get standard basic threshold */ - ret = get_basic_threshold(bthr_name_sc, length, (int *)&thr->basic); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get basic thr fail\n"); - return ret; - } - - /* basic special set by ic */ - if (tdata->func->param_init) { - ret = tdata->func->param_init(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("special basic thr init fail\n"); - return ret; - } - } - - /* init buffer */ - fts_init_buffer(thr->rawdata_min, thr->basic.rawdata_min, node_num, false, 0, 0); - fts_init_buffer(thr->rawdata_max, thr->basic.rawdata_max, node_num, false, 0, 0); - fts_init_buffer(thr->cb_min, thr->basic.cb_min, node_num, false, 0, 0); - fts_init_buffer(thr->cb_max, thr->basic.cb_max, node_num, false, 0, 0); - fts_init_buffer(thr->dcb_sort, 0, node_num, false, 0, 0); - fts_init_buffer(thr->dcb_base, thr->basic.dcb_base, node_num, false, 0, 0); - - /* detail threshold */ - get_detail_threshold("RawDataTest_Min", false, thr->rawdata_min); - get_detail_threshold("RawDataTest_Max", false, thr->rawdata_max); - get_detail_threshold("CbTest_Min", false, thr->cb_min); - get_detail_threshold("CbTest_Max", false, thr->cb_max); - get_detail_threshold("DeltaCxTest_Sort", false, thr->dcb_sort); - get_detail_threshold("DeltaCbTest_Base", false, thr->dcb_base); - - return 0; -} - -static void print_thr_sc(void) -{ - struct fts_test *tdata = fts_ftest; - struct sc_threshold *thr = &tdata->ic.sc.thr; - - if (tdata->ts_data->log_level < 3) { - return; - } - - FTS_TEST_DBG("rawdata_min:%d", thr->basic.rawdata_min); - FTS_TEST_DBG("rawdata_max:%d", thr->basic.rawdata_max); - FTS_TEST_DBG("cb_min:%d", thr->basic.cb_min); - FTS_TEST_DBG("cb_max:%d", thr->basic.cb_max); - FTS_TEST_DBG("dcb_differ_max:%d", thr->basic.dcb_differ_max); - FTS_TEST_DBG("dcb_key_check:%d", thr->basic.dcb_key_check); - FTS_TEST_DBG("dcb_key_differ_max:%d", thr->basic.dcb_key_differ_max); - FTS_TEST_DBG("dcb_ds1:%d", thr->basic.dcb_ds1); - FTS_TEST_DBG("dcb_ds2:%d", thr->basic.dcb_ds2); - FTS_TEST_DBG("dcb_ds3:%d", thr->basic.dcb_ds3); - FTS_TEST_DBG("dcb_ds4:%d", thr->basic.dcb_ds4); - FTS_TEST_DBG("dcb_ds5:%d", thr->basic.dcb_ds5); - FTS_TEST_DBG("dcb_ds6:%d", thr->basic.dcb_ds6); - FTS_TEST_DBG("dcb_critical_check:%d", thr->basic.dcb_critical_check); - FTS_TEST_DBG("dcb_cs1:%d", thr->basic.dcb_cs1); - FTS_TEST_DBG("dcb_cs2:%d", thr->basic.dcb_cs2); - FTS_TEST_DBG("dcb_cs3:%d", thr->basic.dcb_cs3); - FTS_TEST_DBG("dcb_cs4:%d", thr->basic.dcb_cs4); - FTS_TEST_DBG("dcb_cs5:%d", thr->basic.dcb_cs5); - FTS_TEST_DBG("dcb_cs6:%d", thr->basic.dcb_cs6); - - print_buffer(thr->rawdata_min, tdata->node.node_num, tdata->node.rx_num); - print_buffer(thr->rawdata_max, tdata->node.node_num, tdata->node.rx_num); - print_buffer(thr->cb_min, tdata->node.node_num, tdata->node.rx_num); - print_buffer(thr->cb_max, tdata->node.node_num, tdata->node.rx_num); - print_buffer(thr->dcb_sort, tdata->node.node_num, tdata->node.rx_num); - print_buffer(thr->dcb_base, tdata->node.node_num, tdata->node.rx_num); -} - -static int ini_init_test_sc(void) -{ - int ret = 0; - - ret = get_test_item_sc(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get sc test item fail\n"); - return ret; - } - - ret = get_test_threshold_sc(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get sc threshold fail\n"); - return ret; - } - - print_thr_sc(); - return 0; -} - -static u32 ini_get_ic_code(char *ic_name) -{ - int i = 0; - int type_size = 0; - int ini_icname_len = 0; - int ic_types_len = 0; - - ini_icname_len = strlen(ic_name); - type_size = sizeof(ic_types) / sizeof(ic_types[0]); - for (i = 0; i < type_size; i++) { - ic_types_len = strlen(ic_name); - if (ini_icname_len == ic_types_len) { - if (0 == strncmp(ic_name, ic_types[i].ic_name, ic_types_len)) - return ic_types[i].ic_type; - } - } - - FTS_TEST_ERROR("no IC type match"); - return 0; -} - - -static void ini_init_interface(struct ini_data *ini) -{ - char str[MAX_KEYWORD_VALUE_LEN] = { 0 }; - u32 value = 0; - struct fts_test *tdata = fts_ftest; - - /* IC type */ - ini_get_string_value("Interface", "IC_Type", str); - snprintf(ini->ic_name, MAX_IC_NAME_LEN, "%s", str); - - value = ini_get_ic_code(str); - ini->ic_code = value; - FTS_TEST_INFO("ic name:%s, ic code:%x", ini->ic_name, ini->ic_code); - - if (IC_HW_MC_SC == tdata->func->hwtype) { - get_value_interface("Normalize_Type", &value); - tdata->normalize = (u8)value; - FTS_TEST_DBG("normalize:%d", tdata->normalize); - } -} - -static int ini_init_test(struct ini_data *ini) -{ - int ret = 0; - struct fts_test *tdata = fts_ftest; - - /* interface init */ - ini_init_interface(ini); - - /* node valid */ - ret = init_node_valid(); - if (ret < 0) { - FTS_TEST_ERROR("init node valid fail"); - return ret; - } - - switch (tdata->func->hwtype) { - case IC_HW_INCELL: - ret = ini_init_test_incell(); - break; - case IC_HW_MC_SC: - ret = ini_init_test_mc_sc(); - break; - case IC_HW_SC: - ret = ini_init_test_sc(); - break; - default: - FTS_TEST_SAVE_ERR("test ic type(%d) fail\n", tdata->func->hwtype); - ret = -EINVAL; - break; - } - - return ret; -} - -/* - * fts_test_get_testparam_from_ini - get test parameters from ini - * - * read, parse the configuration file, initialize the test variable - * - * return 0 if succuss, else errro code - */ -int fts_test_get_testparam_from_ini(char *config_name) -{ - int ret = 0; - struct ini_data *ini = &fts_ftest->ini; - - ret = fts_test_get_ini_via_request_firmware(ini, config_name); - if (ret != 0) { - ret = fts_test_get_ini_default(ini, config_name); - if (ret < 0) { - FTS_TEST_ERROR("get ini(default) fail"); - goto get_ini_err; - } - } - - ini->keyword_num_total = 0; - ini->section_num = 0; - - ini->tmp = vmalloc(sizeof(struct ini_keyword) * MAX_KEYWORD_NUM); - if (NULL == ini->tmp) { - FTS_TEST_ERROR("malloc memory for ini tmp fail"); - ret = -ENOMEM; - goto get_ini_err; - } - memset(ini->tmp, 0, sizeof(struct ini_keyword) * MAX_KEYWORD_NUM); - - /* parse ini data to get keyword name&value */ - ret = ini_init_inidata(ini); - if (ret < 0) { - FTS_TEST_ERROR("ini_init_inidata fail"); - goto get_ini_err; - } - - /* parse threshold & test item */ - ret = ini_init_test(ini); - if (ret < 0) { - FTS_TEST_ERROR("ini init fail"); - goto get_ini_err; - } - - ret = 0; -get_ini_err: - if (ini->tmp) { - vfree(ini->tmp); - ini->tmp = NULL; - } - - if (ini->data) { - vfree(ini->data); - ini->data = NULL; - } - - return ret; -} diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/focaltech_test_ini.h b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/focaltech_test_ini.h deleted file mode 100755 index 13677b23360a..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/focaltech_test_ini.h +++ /dev/null @@ -1,141 +0,0 @@ -/************************************************************************ -* Copyright (C) 2012-2019, Focaltech Systems (R)£¬All Rights Reserved. -* -* File Name: focaltech_test_ini.h -* -* Author: Focaltech Driver Team -* -* Created: 2016-08-01 -* -* Abstract: parsing function of INI file -* -************************************************************************/ -#ifndef _INI_H -#define _INI_H -/***************************************************************************** -* Private constant and macro definitions using #define -*****************************************************************************/ -#define MAX_KEYWORD_NUM (1000) -#define MAX_KEYWORD_NAME_LEN (50) -#define MAX_KEYWORD_VALUE_LEN (512) -#define MAX_KEYWORD_VALUE_ONE_LEN (16) -#define MAX_INI_LINE_LEN (MAX_KEYWORD_NAME_LEN + MAX_KEYWORD_VALUE_LEN) -#define MAX_INI_SECTION_NUM (20) -#define MAX_IC_NAME_LEN (32) -#define MAX_TEST_ITEM (20) -#define IC_CODE_OFFSET (16) - -/***************************************************************************** -* enumerations, structures and unions -*****************************************************************************/ -struct ini_ic_type { - char ic_name[MAX_IC_NAME_LEN]; - u32 ic_type; -}; - -enum line_type { - LINE_SECTION = 1, - LINE_KEYWORD = 2 , - LINE_OTHER = 3, -}; - -struct ini_keyword { - char name[MAX_KEYWORD_NAME_LEN]; - char value[MAX_KEYWORD_VALUE_LEN]; -}; - -struct ini_section { - char name[MAX_KEYWORD_NAME_LEN]; - int keyword_num; - /* point to ini.tmp, don't need free */ - struct ini_keyword *keyword; -}; - -struct ini_data { - char *data; - int length; - int keyword_num_total; - int section_num; - struct ini_section section[MAX_INI_SECTION_NUM]; - struct ini_keyword *tmp; - char ic_name[MAX_IC_NAME_LEN]; - u32 ic_code; -}; - -#define TEST_ITEM_INCELL { \ - "SHORT_CIRCUIT_TEST", \ - "OPEN_TEST", \ - "CB_TEST", \ - "RAWDATA_TEST", \ - "LCD_NOISE_TEST", \ - "KEY_SHORT_TEST", \ - "MUX_OPEN_TEST", \ -} - -#define BASIC_THRESHOLD_INCELL { \ - "ShortCircuit_ResMin", "ShortCircuit_VkResMin", \ - "OpenTest_CBMin", "OpenTest_Check_K1", "OpenTest_K1Threshold", "OpenTest_Check_K2", "OpenTest_K2Threshold", \ - "CBTest_Min", "CBTest_Max", \ - "CBTest_VKey_Check", "CBTest_Min_Vkey", "CBTest_Max_Vkey", \ - "RawDataTest_Min", "RawDataTest_Max", \ - "RawDataTest_VKey_Check", "RawDataTest_Min_VKey", "RawDataTest_Max_VKey", \ - "LCD_NoiseTest_Frame", "LCD_NoiseTest_Coefficient", "LCD_NoiseTest_Coefficient_key", \ -} - - -#define TEST_ITEM_MC_SC { \ - "RAWDATA_TEST", \ - "UNIFORMITY_TEST", \ - "SCAP_CB_TEST", \ - "SCAP_RAWDATA_TEST", \ - "WEAK_SHORT_CIRCUIT_TEST", \ - "PANEL_DIFFER_TEST", \ -} - -#define BASIC_THRESHOLD_MC_SC { \ - "RawDataTest_High_Min", "RawDataTest_High_Max", "RawDataTest_HighFreq", \ - "RawDataTest_Low_Min", "RawDataTest_Low_Max", "RawDataTest_LowFreq", \ - "UniformityTest_Check_Tx", "UniformityTest_Check_Rx","UniformityTest_Check_MinMax", \ - "UniformityTest_Tx_Hole", "UniformityTest_Rx_Hole", "UniformityTest_MinMax_Hole", \ - "SCapCbTest_OFF_Min", "SCapCbTest_OFF_Max", "ScapCBTest_SetWaterproof_OFF", \ - "SCapCbTest_ON_Min", "SCapCbTest_ON_Max", "ScapCBTest_SetWaterproof_ON", \ - "SCapRawDataTest_OFF_Min", "SCapRawDataTest_OFF_Max", "SCapRawDataTest_SetWaterproof_OFF", \ - "SCapRawDataTest_ON_Min", "SCapRawDataTest_ON_Max", "SCapRawDataTest_SetWaterproof_ON", \ - "WeakShortTest_CG", "WeakShortTest_CC", \ - "PanelDifferTest_Min", "PanelDifferTest_Max", \ -} - -#define TEST_ITEM_SC { \ - "RAWDATA_TEST", \ - "CB_TEST", \ - "DELTA_CB_TEST", \ - "WEAK_SHORT_TEST", \ -} - -#define BASIC_THRESHOLD_SC { \ - "RawDataTest_Min", "RawDataTest_Max", \ - "CbTest_Min", "CbTest_Max", \ - "DeltaCbTest_Base", "DeltaCbTest_Differ_Max", \ - "DeltaCbTest_Include_Key_Test", "DeltaCbTest_Key_Differ_Max", \ - "DeltaCbTest_Deviation_S1", "DeltaCbTest_Deviation_S2", "DeltaCbTest_Deviation_S3", \ - "DeltaCbTest_Deviation_S4", "DeltaCbTest_Deviation_S5", "DeltaCbTest_Deviation_S6", \ - "DeltaCbTest_Set_Critical", "DeltaCbTest_Critical_S1", "DeltaCbTest_Critical_S2", \ - "DeltaCbTest_Critical_S3", "DeltaCbTest_Critical_S4", \ - "DeltaCbTest_Critical_S5", "DeltaCbTest_Critical_S6", \ -} - -/***************************************************************************** -* Global variable or extern global variabls/functions -*****************************************************************************/ -int fts_test_get_testparam_from_ini(char *config_name); -int get_keyword_value(char *section, char *name, int *value); - -#define get_value_interface(name, value) \ - get_keyword_value("Interface", name, value) -#define get_value_basic(name, value) \ - get_keyword_value("Basic_Threshold", name, value) -#define get_value_detail(name, value) \ - get_keyword_value("SpecialSet", name, value) -#define get_value_testitem(name, value) \ - get_keyword_value("TestItem", name, value) -#endif /* _INI_H */ diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/supported_ic/Makefile b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/supported_ic/Makefile deleted file mode 100755 index e913de1de94b..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/supported_ic/Makefile +++ /dev/null @@ -1 +0,0 @@ -obj-$(CONFIG_TOUCHSCREEN_FTS) += focaltech_test_ft8719.o \ No newline at end of file diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/supported_ic/focaltech_test_ft8719.c b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/supported_ic/focaltech_test_ft8719.c deleted file mode 100755 index fcc162fbf93c..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/supported_ic/focaltech_test_ft8719.c +++ /dev/null @@ -1,618 +0,0 @@ -/************************************************************************ -* Copyright (C) 2012-2019, Focaltech Systems (R), All Rights Reserved. -* -* File Name: Focaltech_test_ft8719.c -* -* Author: Focaltech Driver Team -* -* Created: 2017-12-01 -* -* Abstract: -* -************************************************************************/ - -/***************************************************************************** -* Included header files -*****************************************************************************/ -#include "../focaltech_test.h" - -/******************************************************************************* -* Private constant and macro definitions using #define -*******************************************************************************/ -#define CODE2_SHORT_TEST 14 -#define CODE2_OPEN_TEST 24 -#define CODE2_LCD_NOISE_TEST 15 - -/******************************************************************************* -* Private enumerations, structures and unions using typedef -*******************************************************************************/ - -/******************************************************************************* -* Static variables -*******************************************************************************/ - -/******************************************************************************* -* Global variable or extern global variabls/functions -*******************************************************************************/ - -/******************************************************************************* -* Static function prototypes -*******************************************************************************/ -static int ft8719_short_test(struct fts_test *tdata, bool *test_result) -{ - int ret = 0; - int i = 0; - bool tmp_result = false; - int byte_num = 0; - int ch_num = 0; - int min = 0; - int max = 0; - int tmp_adc = 0; - int *adcdata = NULL; - struct incell_threshold *thr = &tdata->ic.incell.thr; - - FTS_TEST_FUNC_ENTER(); - FTS_TEST_SAVE_INFO("\n============ Test Item: Short Circuit Test\n"); - memset(tdata->buffer, 0, tdata->buffer_length); - adcdata = tdata->buffer; - - ret = enter_factory_mode(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("enter factory mode fail,ret=%d\n", ret); - goto test_err; - } - - byte_num = tdata->node.node_num * 2; - ch_num = tdata->node.rx_num; - ret = short_get_adcdata_incell(TEST_RETVAL_AA, ch_num, byte_num, adcdata); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get adc data fail\n"); - goto test_err; - } - - /* calculate resistor */ - for (i = 0; i < tdata->node.node_num; i++) { - tmp_adc = adcdata[i]; - if (tmp_adc < 50) { - adcdata[i] = -1; - continue; - } else if (tmp_adc < 200) { - tmp_adc = 200; - } - - adcdata[i] = 252000 / (tmp_adc - 120) - 60; - } - - /* save */ - show_data(adcdata, true); - - /* compare */ - min = thr->basic.short_res_min; - max = TEST_SHORT_RES_MAX; - tmp_result = compare_data(adcdata, min, max, min, max, true); - - ret = 0; -test_err: - if (tmp_result) { - *test_result = true; - FTS_TEST_SAVE_INFO("------ Short Circuit Test PASS\n"); - } else { - *test_result = false; - FTS_TEST_SAVE_INFO("------ Short Circuit Test NG\n"); - } - - /*save test data*/ - fts_test_save_data("Short Circuit Test", CODE2_SHORT_TEST, - adcdata, 0, false, true, *test_result); - FTS_TEST_FUNC_EXIT(); - return ret; -} - -static int ft8719_open_test(struct fts_test *tdata, bool *test_result) -{ - int ret = 0; - bool tmp_result = false; - int byte_num = 0; - u8 reg20_val = 0; - u8 reg21_val = 0; - u8 k1 = 0; - u8 k2 = 0; - int min = 0; - int max = 0; - int *opendata = NULL; - struct incell_threshold *thr = &tdata->ic.incell.thr; - - FTS_TEST_FUNC_ENTER(); - FTS_TEST_SAVE_INFO("\n============ Test Item: Open Test\n"); - memset(tdata->buffer, 0, tdata->buffer_length); - opendata = tdata->buffer; - - ret = enter_factory_mode(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("enter factory mode fail,ret=%d\n", ret); - goto test_err; - } - - /* backup defaul value */ - ret = fts_test_read_reg(FACTORY_REG_OPEN_REG20, ®20_val); - if (ret < 0) { - FTS_TEST_SAVE_ERR("read reg 0x20 fail\n"); - goto test_err; - } - ret = fts_test_read_reg(FACTORY_REG_OPEN_REG21, ®21_val); - if (ret < 0) { - FTS_TEST_SAVE_ERR("read reg 0x21 fail\n"); - goto test_err; - } - if (thr->basic.open_k1_check) { - ret = fts_test_read_reg(FACTORY_REG_K1, &k1); - if (ret < 0) { - FTS_TEST_SAVE_ERR("read k1 fail\n"); - goto test_err; - } - } - if (thr->basic.open_k2_check) { - ret = fts_test_read_reg(FACTORY_REG_K2, &k2); - if (ret < 0) { - FTS_TEST_SAVE_ERR("read k2 fail\n"); - goto test_err; - } - } - - /* open test enable */ - ret = fts_test_write_reg(FACTORY_REG_OPEN_TEST_EN, 0x01); - if (ret < 0) { - FTS_TEST_SAVE_ERR("open test enable fail\n"); - goto test_err; - } - - /* set open test environment */ - ret = fts_test_write_reg(FACTORY_REG_OPEN_REG20, 0x01); - if (ret < 0) { - FTS_TEST_SAVE_ERR("write reg 0x20 fail\n"); - goto restore_reg; - } - - ret = fts_test_write_reg(FACTORY_REG_OPEN_REG21, 0x01); - if (ret < 0) { - FTS_TEST_SAVE_ERR("write reg 0x21 fail\n"); - goto restore_reg; - } - - if (thr->basic.open_k1_check) { - ret = fts_test_write_reg(FACTORY_REG_K1, thr->basic.open_k1_value); - if (ret < 0) { - FTS_TEST_SAVE_ERR("write reg k1 fail\n"); - goto restore_reg; - } - } - - if (thr->basic.open_k2_check) { - ret = fts_test_write_reg(FACTORY_REG_K2, thr->basic.open_k2_value); - if (ret < 0) { - FTS_TEST_SAVE_ERR("write reg k2 fail\n"); - goto restore_reg; - } - } - - /* wait fw state update before clb */ - ret = wait_state_update(TEST_RETVAL_00); - if (ret < 0) { - FTS_TEST_SAVE_ERR("wait state update fail\n"); - goto restore_reg; - } - /* auto clb */ - ret = chip_clb(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("auto clb fail\n"); - goto restore_reg; - } - - /* get cb data */ - byte_num = tdata->node.tx_num * tdata->node.rx_num; - ret = get_cb_incell(0, byte_num, opendata); - if (ret) { - FTS_TEST_SAVE_ERR("get CB fail\n"); - goto restore_reg; - } - - /* save */ - show_data(opendata, false); - - /* compare */ - min = thr->basic.open_cb_min; - max = TEST_OPEN_MAX_VALUE; - tmp_result = compare_data(opendata, min, max, 0, 0, false); - -restore_reg: - ret = fts_test_write_reg(FACTORY_REG_OPEN_REG20, reg20_val); - if (ret < 0) { - FTS_TEST_SAVE_ERR("restore reg 0x20 fail\n"); - } - - ret = fts_test_write_reg(FACTORY_REG_OPEN_REG21, reg21_val); - if (ret < 0) { - FTS_TEST_SAVE_ERR("restore reg 0x21 fail\n"); - } - - if (thr->basic.open_k1_check) { - ret = fts_test_write_reg(FACTORY_REG_K1, k1); - if (ret < 0) { - FTS_TEST_SAVE_ERR("restore reg k1 fail\n"); - } - } - - if (thr->basic.open_k2_check) { - ret = fts_test_write_reg(FACTORY_REG_K2, k2); - if (ret < 0) { - FTS_TEST_SAVE_ERR("restore reg k2 fail\n"); - } - } - - /* open test disable */ - ret = fts_test_write_reg(FACTORY_REG_OPEN_TEST_EN, 0x00); - if (ret < 0) { - FTS_TEST_SAVE_ERR("open test disable fail\n"); - } - - /* wait fw state update before clb */ - ret = wait_state_update(TEST_RETVAL_00); - if (ret < 0) { - FTS_TEST_SAVE_ERR("wait state update fail\n"); - } - /* auto clb */ - ret = chip_clb(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("auto clb fail\n"); - } - -test_err: - if (tmp_result) { - *test_result = true; - FTS_TEST_SAVE_INFO("------ Open Test PASS\n"); - } else { - *test_result = false; - FTS_TEST_SAVE_INFO("------ Open Test NG\n"); - } - - /* save test data */ - fts_test_save_data("Open Test", CODE2_OPEN_TEST, - opendata, 0, false, false, *test_result); - - FTS_TEST_FUNC_EXIT(); - return ret; -} - -static int ft8719_cb_test(struct fts_test *tdata, bool *test_result) -{ - int ret = 0; - bool tmp_result = false; - bool key_check = false; - int byte_num = 0; - int *cbdata = NULL; - struct incell_threshold *thr = &tdata->ic.incell.thr; - - FTS_TEST_FUNC_ENTER(); - FTS_TEST_SAVE_INFO("\n============ Test Item: CB Test\n"); - memset(tdata->buffer, 0, tdata->buffer_length); - cbdata = tdata->buffer; - key_check = thr->basic.cb_vkey_check; - - if (!thr->cb_min || !thr->cb_max || !test_result) { - FTS_TEST_SAVE_ERR("cb_min/max test_result is null\n"); - ret = -EINVAL; - goto test_err; - } - - ret = enter_factory_mode(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("enter factory mode fail,ret=%d\n", ret); - goto test_err; - } - - /* cb test enable */ - ret = fts_test_write_reg(FACTORY_REG_CB_TEST_EN, 0x01); - if (ret < 0) { - FTS_TEST_SAVE_ERR("cb test enable fail\n"); - goto test_err; - } - - /* auto clb */ - ret = chip_clb(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("auto clb fail\n"); - goto test_err; - } - - byte_num = tdata->node.node_num; - ret = get_cb_incell(0, byte_num, cbdata); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get cb fail\n"); - goto test_err; - } - - /* save */ - show_data(cbdata, key_check); - - /* compare */ - tmp_result = compare_array(cbdata, thr->cb_min, thr->cb_max, key_check); - -test_err: - /* cb test disable */ - ret = fts_test_write_reg(FACTORY_REG_CB_TEST_EN, 0x00); - if (ret < 0) { - FTS_TEST_SAVE_ERR("cb test disable fail\n"); - } - - if (tmp_result) { - *test_result = true; - FTS_TEST_SAVE_INFO("------ CB Test PASS\n"); - } else { - *test_result = false; - FTS_TEST_SAVE_INFO("------ CB Test NG\n"); - } - - /* save test data */ - fts_test_save_data("CB Test", CODE_CB_TEST, - cbdata, 0, false, key_check, *test_result); - - FTS_TEST_FUNC_EXIT(); - return ret; -} - -static int ft8719_rawdata_test(struct fts_test *tdata, bool *test_result) -{ - int ret = 0; - int i = 0; - bool tmp_result = false; - bool key_check = false; - int *rawdata = NULL; - struct incell_threshold *thr = &tdata->ic.incell.thr; - - FTS_TEST_FUNC_ENTER(); - FTS_TEST_SAVE_INFO("\n============ Test Item: RawData Test\n"); - memset(tdata->buffer, 0, tdata->buffer_length); - rawdata = tdata->buffer; - key_check = thr->basic.rawdata_vkey_check; - - if (!thr->rawdata_min || !thr->rawdata_max || !test_result) { - FTS_TEST_SAVE_ERR("rawdata_min/max test_result is null\n"); - ret = -EINVAL; - goto test_err; - } - - ret = enter_factory_mode(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("enter factory mode fail,ret=%d\n", ret); - goto test_err; - } - - /* rawdata test enable */ - ret = fts_test_write_reg(FACTORY_REG_RAWDATA_TEST_EN, 0x01); - if (ret < 0) { - FTS_TEST_SAVE_ERR("rawdata test enable fail\n"); - goto test_err; - } - - /* read rawdata */ - for (i = 0 ; i < 3; i++) { - ret = get_rawdata(rawdata); - } - if (ret < 0) { - FTS_TEST_SAVE_ERR("get RawData fail,ret=%d\n", ret); - goto test_err; - } - - /* save */ - show_data(rawdata, key_check); - - /* compare */ - tmp_result = compare_array(rawdata, - thr->rawdata_min, - thr->rawdata_max, - key_check); - -test_err: - /* rawdata test disble */ - ret = fts_test_write_reg(FACTORY_REG_RAWDATA_TEST_EN, 0x00); - if (ret < 0) { - FTS_TEST_SAVE_ERR("rawdata test disable fail\n"); - } - - if (tmp_result) { - *test_result = true; - FTS_TEST_SAVE_INFO("------ RawData Test PASS\n"); - } else { - *test_result = false; - FTS_TEST_SAVE_INFO("------ RawData Test NG\n"); - } - - /* save test data */ - fts_test_save_data("RawData Test", CODE_RAWDATA_TEST, - rawdata, 0, false, key_check, *test_result); - - FTS_TEST_FUNC_EXIT(); - return ret; -} - -static int ft8719_lcdnoise_test(struct fts_test *tdata, bool *test_result) -{ - int ret = 0; - int i = 0; - bool tmp_result = false; - int byte_num = 0; - u8 old_mode = 0; - u8 status = 0; - int frame_num = 0; - int max = 0; - int max_vk = 0; - int *lcdnoise = NULL; - struct incell_threshold *thr = &tdata->ic.incell.thr; - - FTS_TEST_FUNC_ENTER(); - FTS_TEST_SAVE_INFO("\n============ Test Item: LCD Noise Test\n"); - memset(tdata->buffer, 0, tdata->buffer_length); - lcdnoise = tdata->buffer; - - ret = enter_factory_mode(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("enter factory mode fail,ret=%d\n", ret); - goto test_err; - } - - ret = fts_test_read_reg(FACTORY_REG_DATA_SELECT, &old_mode); - if (ret < 0) { - FTS_TEST_SAVE_ERR("read reg06 fail\n"); - goto test_err; - } - - ret = fts_test_write_reg(FACTORY_REG_DATA_SELECT, 0x01); - if (ret < 0) { - FTS_TEST_SAVE_ERR("write 1 to reg06 fail\n"); - goto restore_reg; - } - - ret = fts_test_write_reg(FACTORY_REG_LINE_ADDR, 0xAD); - if (ret < 0) { - FTS_TEST_SAVE_ERR("write reg01 fail\n"); - goto restore_reg; - } - - frame_num = thr->basic.lcdnoise_frame; - ret = fts_test_write_reg(FACTORY_REG_LCD_NOISE_FRAME, frame_num / 4); - if (ret < 0) { - FTS_TEST_SAVE_INFO("write frame num fail\n"); - goto restore_reg; - } - - /* start test */ - ret = fts_test_write_reg(FACTORY_REG_LCD_NOISE_START, 0x01); - if (ret < 0) { - FTS_TEST_SAVE_INFO("start lcdnoise test fail\n"); - goto restore_reg; - } - - /* check test status */ - sys_delay(frame_num * FACTORY_TEST_DELAY / 2); - for (i = 0; i < FACTORY_TEST_RETRY; i++) { - status = 0xFF; - ret = fts_test_read_reg(FACTORY_REG_LCD_NOISE_START, &status); - if ((ret >= 0) && (TEST_RETVAL_AA == status)) { - break; - } else { - FTS_TEST_DBG("reg%x=%x,retry:%d\n", - FACTORY_REG_LCD_NOISE_START, status, i); - } - sys_delay(FACTORY_TEST_RETRY_DELAY); - } - if (i >= FACTORY_TEST_RETRY) { - FTS_TEST_SAVE_ERR("lcdnoise test timeout\n"); - goto restore_reg; - } - /* read lcdnoise */ - byte_num = tdata->node.node_num * 2; - ret = read_mass_data(FACTORY_REG_RAWDATA_ADDR, byte_num, lcdnoise); - if (ret < 0) { - FTS_TEST_SAVE_ERR("read rawdata fail\n"); - goto restore_reg; - } - - /* save */ - show_data(lcdnoise, true); - - /* compare */ - max = thr->basic.lcdnoise_coefficient * tdata->va_touch_thr * 32 / 100; - max_vk = thr->basic.lcdnoise_coefficient_vkey * tdata->vk_touch_thr * 32 / 100; - tmp_result = compare_data(lcdnoise, 0, max, 0, max_vk, true); - -restore_reg: - ret = fts_test_write_reg(FACTORY_REG_LCD_NOISE_START, 0x00); - if (ret < 0) { - FTS_TEST_SAVE_ERR("write 0 to reg11 fail\n"); - } - - ret = fts_test_write_reg(FACTORY_REG_DATA_SELECT, old_mode); - if (ret < 0) { - FTS_TEST_SAVE_ERR("restore reg06 fail\n"); - } -test_err: - if (tmp_result) { - *test_result = true; - FTS_TEST_SAVE_INFO("------ LCD Noise Test PASS\n"); - } else { - *test_result = false; - FTS_TEST_SAVE_INFO("------ LCD Noise Test NG\n"); - } - - /* save test data */ - fts_test_save_data("LCD Noise Test", CODE2_LCD_NOISE_TEST, - lcdnoise, 0, false, true, *test_result); - FTS_TEST_FUNC_EXIT(); - return ret; -} - -static int start_test_ft8719(void) -{ - int ret = 0; - struct fts_test *tdata = fts_ftest; - struct incell_testitem *test_item = &tdata->ic.incell.u.item; - bool temp_result = false; - bool test_result = true; - - FTS_TEST_FUNC_ENTER(); - FTS_TEST_INFO("test item:0x%x", fts_ftest->ic.incell.u.tmp); - - if (!tdata || !tdata->buffer) { - FTS_TEST_ERROR("tdata is null"); - return -EINVAL; - } - - /* short test */ - if (true == test_item->short_test) { - ret = ft8719_short_test(tdata, &temp_result); - if ((ret < 0) || (false == temp_result)) { - test_result = false; - } - } - - /* open test */ - if (true == test_item->open_test) { - ret = ft8719_open_test(tdata, &temp_result); - if ((ret < 0) || (false == temp_result)) { - test_result = false; - } - } - - /* cb test */ - if (true == test_item->cb_test) { - ret = ft8719_cb_test(tdata, &temp_result); - if ((ret < 0) || (false == temp_result)) { - test_result = false; - } - } - - /* rawdata test */ - if (true == test_item->rawdata_test) { - ret = ft8719_rawdata_test(tdata, &temp_result); - if ((ret < 0) || (false == temp_result)) { - test_result = false; - } - } - - /* lcd noise test */ - if (true == test_item->lcdnoise_test) { - ret = ft8719_lcdnoise_test(tdata, &temp_result); - if ((ret < 0) || (false == temp_result)) { - test_result = false; - } - } - - return test_result; -} - -struct test_funcs test_func_ft8719 = { - .ctype = {0x0D, 0x0F}, - .hwtype = IC_HW_INCELL, - .key_num_total = 4, - .start_test = start_test_ft8719, -}; diff --git a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/supported_ic/focaltech_test_ft8756.c b/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/supported_ic/focaltech_test_ft8756.c deleted file mode 100644 index 2f70bd93f38e..000000000000 --- a/drivers/input/touchscreen/focaltech_0flash_8756_mmi/focaltech_test/supported_ic/focaltech_test_ft8756.c +++ /dev/null @@ -1,578 +0,0 @@ -/************************************************************************ -* Copyright (C) 2012-2019, Focaltech Systems (R), All Rights Reserved. -* -* File Name: Focaltech_test_ft8756.c -* -* Author: Focaltech Driver Team -* -* Created: 2019-03-02 -* -* Abstract: -* -************************************************************************/ - -/***************************************************************************** -* Included header files -*****************************************************************************/ -#include "../focaltech_test.h" - -/***************************************************************************** -* Private constant and macro definitions using #define -*****************************************************************************/ - -/***************************************************************************** -* Private constant and macro definitions using #define -*****************************************************************************/ - -/***************************************************************************** -* Private enumerations, structures and unions using typedef -*****************************************************************************/ - -/***************************************************************************** -* Static variables -*****************************************************************************/ - -/***************************************************************************** -* Global variable or extern global variabls/functions -*****************************************************************************/ - -/***************************************************************************** -* Static function prototypes -*****************************************************************************/ -static int ft8756_short_test(struct fts_test *tdata, bool *test_result) -{ - int ret = 0; - int i = 0; - bool tmp_result = false; - int byte_num = 0; - int ch_num = 0; - int min = 0; - int max = 0; - int tmp_adc = 0; - int *adcdata = NULL; - struct incell_threshold *thr = &tdata->ic.incell.thr; - - FTS_TEST_FUNC_ENTER(); - FTS_TEST_SAVE_INFO("\n============ Test Item: Short Circuit Test\n"); - memset(tdata->buffer, 0, tdata->buffer_length); - adcdata = tdata->buffer; - - ret = enter_factory_mode(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("enter factory mode fail,ret=%d\n", ret); - goto test_err; - } - - byte_num = tdata->node.node_num * 2; - ch_num = tdata->node.rx_num; - ret = short_get_adcdata_incell(TEST_RETVAL_AA, ch_num, byte_num, adcdata); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get adc data fail\n"); - goto test_err; - } - - /* calculate resistor */ - for (i = 0; i < tdata->node.node_num; i++) { - tmp_adc = adcdata[i]; - if (tmp_adc > 3500) { - tmp_adc = 3500; - } - adcdata[i] = (5160960 + 555 * 32 * tmp_adc) / (1146880 - 320 * tmp_adc); - } - - /* save */ - show_data(adcdata, false); - - /* compare */ - min = thr->basic.short_res_min; - max = TEST_SHORT_RES_MAX; - tmp_result = compare_data(adcdata, min, max, min, max, false); - - ret = 0; -test_err: - ret = fts_test_write_reg(FACTORY_REG_SHORT_TEST_STATE, 0x03); - if (ret < 0) { - FTS_TEST_SAVE_ERR("write idle to short test state fail\n"); - } - - if (tmp_result) { - *test_result = true; - FTS_TEST_SAVE_INFO("------ Short Circuit Test PASS\n"); - } else { - *test_result = false; - FTS_TEST_SAVE_INFO("------ Short Circuit Test NG\n"); - } - - /* save test data */ - fts_test_save_data("Short Circuit Test", CODE_SHORT_TEST, - adcdata, 0, false, false, *test_result); - - FTS_TEST_FUNC_EXIT(); - return ret; -} - -static int ft8756_open_test(struct fts_test *tdata, bool *test_result) -{ - int ret = 0; - int i = 0; - bool tmp_result = false; - u8 state = 0; - int byte_num = 0; - int min = 0; - int max = 0; - u8 k1 = 0; - u8 k2 = 0; - int *opendata = NULL; - struct incell_threshold *thr = &tdata->ic.incell.thr; - - FTS_TEST_FUNC_ENTER(); - FTS_TEST_SAVE_INFO("\n============ Test Item: Open Test\n"); - memset(tdata->buffer, 0, tdata->buffer_length); - opendata = tdata->buffer; - - ret = enter_factory_mode(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("enter factory mode fail,ret=%d\n", ret); - goto test_err; - } - - if (thr->basic.open_k1_check) { - ret = fts_test_read_reg(FACTORY_REG_K1, &k1); - if (ret < 0) { - FTS_TEST_SAVE_ERR("read k1 fail\n"); - goto test_err; - } - } - if (thr->basic.open_k2_check) { - ret = fts_test_read_reg(FACTORY_REG_K2, &k2); - if (ret < 0) { - FTS_TEST_SAVE_ERR("read k2 fail\n"); - goto restore_reg; - } - } - - if (thr->basic.open_k1_check) { - ret = fts_test_write_reg(FACTORY_REG_K1, thr->basic.open_k1_value); - if (ret < 0) { - FTS_TEST_SAVE_ERR("write reg k1 fail\n"); - goto restore_reg; - } - } - - if (thr->basic.open_k2_check) { - ret = fts_test_write_reg(FACTORY_REG_K2, thr->basic.open_k2_value); - if (ret < 0) { - FTS_TEST_SAVE_ERR("write reg k2 fail\n"); - goto restore_reg; - } - } - - ret = fts_test_write_reg(FACTORY_REG_OPEN_START, 0x01); - if (ret < 0) { - FTS_TEST_SAVE_ERR("start open test fail\n"); - goto restore_reg; - } - - /* check test status */ - for (i = 0; i < FACTORY_TEST_RETRY; i++) { - sys_delay(FACTORY_TEST_RETRY_DELAY); - ret = fts_test_read_reg(FACTORY_REG_OPEN_STATE, &state); - if ((ret >= 0) && (TEST_RETVAL_AA == state)) { - break; - } else { - FTS_TEST_DBG("reg%x=%x,retry:%d\n", - FACTORY_REG_OPEN_STATE, state, i); - } - } - if (i >= FACTORY_TEST_RETRY) { - FTS_TEST_SAVE_ERR("open test timeout\n"); - goto restore_reg; - } - - /* get cb data */ - byte_num = tdata->node.node_num; - ret = get_cb_incell(0, byte_num, opendata); - if (ret) { - FTS_TEST_SAVE_ERR("get CB fail\n"); - goto restore_reg; - } - - /* save */ - show_data(opendata, false); - - /* compare */ - min = thr->basic.open_cb_min; - max = TEST_OPEN_MAX_VALUE; - tmp_result = compare_data(opendata, min, max, 0, 0, false); - -restore_reg: - /* Restore reg */ - if (thr->basic.open_k1_check) { - ret = fts_test_write_reg(FACTORY_REG_K1, k1); - if (ret < 0) { - FTS_TEST_SAVE_ERR("restore reg k1 fail\n"); - } - } - if (thr->basic.open_k2_check) { - ret = fts_test_write_reg(FACTORY_REG_K2, k2); - if (ret < 0) { - FTS_TEST_SAVE_ERR("restore reg k2 fail\n"); - } - } - - /* auto clb */ - ret = chip_clb(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("auto clb fail\n"); - } - -test_err: - ret = fts_test_write_reg(FACTORY_REG_OPEN_STATE, 0x03); - if (ret < 0) { - FTS_TEST_SAVE_ERR("write idle to open test state fail\n"); - } - - if (tmp_result) { - *test_result = true; - FTS_TEST_SAVE_INFO("------ Open Test PASS\n"); - } else { - *test_result = false; - FTS_TEST_SAVE_INFO("------ Open Test NG\n"); - } - - /*save test data*/ - fts_test_save_data("Open Test", CODE_OPEN_TEST, - opendata, 0, false, false, *test_result); - FTS_TEST_FUNC_EXIT(); - return ret; -} - -static int ft8756_cb_test(struct fts_test *tdata, bool *test_result) -{ - int ret = 0; - bool tmp_result = false; - int byte_num = 0; - int *cbdata = NULL; - struct incell_threshold *thr = &tdata->ic.incell.thr; - - FTS_TEST_FUNC_ENTER(); - FTS_TEST_SAVE_INFO("\n============ Test Item: CB Test\n"); - memset(tdata->buffer, 0, tdata->buffer_length); - cbdata = tdata->buffer; - - if (!thr->cb_min || !thr->cb_max || !test_result) { - FTS_TEST_SAVE_ERR("cb_min/max test_result is null\n"); - ret = -EINVAL; - goto test_err; - } - - ret = enter_factory_mode(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("enter factory mode fail,ret=%d\n", ret); - goto test_err; - } - - /* cb test enable */ - ret = fts_test_write_reg(FACTORY_REG_CB_TEST_EN, 0x01); - if (ret < 0) { - FTS_TEST_SAVE_ERR("cb test enable fail\n"); - goto test_err; - } - - /* auto clb */ - ret = chip_clb(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("auto clb fail\n"); - goto test_err; - } - - byte_num = tdata->node.node_num; - ret = get_cb_incell(0, byte_num, cbdata); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get cb fail\n"); - goto test_err; - } - - /* save */ - show_data(cbdata, false); - - /* compare */ - tmp_result = compare_array(cbdata, thr->cb_min, thr->cb_max, false); - -test_err: - /* cb test disable */ - ret = fts_test_write_reg(FACTORY_REG_CB_TEST_EN, 0x00); - if (ret < 0) { - FTS_TEST_SAVE_ERR("cb test disable fail\n"); - } - - if (tmp_result) { - *test_result = true; - FTS_TEST_SAVE_INFO("------ CB Test PASS\n"); - } else { - *test_result = false; - FTS_TEST_SAVE_INFO("------ CB Test NG\n"); - } - - /*save test data*/ - fts_test_save_data("CB Test", CODE_CB_TEST, - cbdata, 0, false, false, *test_result); - FTS_TEST_FUNC_EXIT(); - return ret; -} - -static int ft8756_rawdata_test(struct fts_test *tdata, bool *test_result) -{ - int ret = 0; - bool tmp_result = false; - int *rawdata = NULL; - struct incell_threshold *thr = &tdata->ic.incell.thr; - - FTS_TEST_FUNC_ENTER(); - FTS_TEST_SAVE_INFO("\n============ Test Item: RawData Test\n"); - memset(tdata->buffer, 0, tdata->buffer_length); - rawdata = tdata->buffer; - - if (!thr->rawdata_min || !thr->rawdata_max || !test_result) { - FTS_TEST_SAVE_ERR("rawdata_min/max test_result is null\n"); - ret = -EINVAL; - goto test_err; - } - - ret = enter_factory_mode(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("enter factory mode fail,ret=%d\n", ret); - goto test_err; - } - - /* rawdata test enable */ - ret = fts_test_write_reg(FACTORY_REG_RAWDATA_TEST_EN, 0x01); - if (ret < 0) { - FTS_TEST_SAVE_ERR("rawdata test enable fail\n"); - goto test_err; - } - - /* read rawdata */ - ret = get_rawdata(rawdata); - if (ret < 0) { - FTS_TEST_SAVE_ERR("get RawData fail,ret=%d\n", ret); - goto test_err; - } - - /* save */ - show_data(rawdata, false); - - /* compare */ - tmp_result = compare_array(rawdata, - thr->rawdata_min, - thr->rawdata_max, - false); - ret = 0; - -test_err: - /* rawdata test disble */ - ret = fts_test_write_reg(FACTORY_REG_RAWDATA_TEST_EN, 0x00); - if (ret < 0) { - FTS_TEST_SAVE_ERR("rawdata test disable fail\n"); - } - - if (tmp_result) { - *test_result = true; - FTS_TEST_SAVE_INFO("------ RawData Test PASS\n"); - } else { - *test_result = false; - FTS_TEST_SAVE_INFO("------ RawData Test NG\n"); - } - - /*save test data*/ - fts_test_save_data("RawData Test", CODE_RAWDATA_TEST, - rawdata, 0, false, false, *test_result); - FTS_TEST_FUNC_EXIT(); - return ret; -} - -static int ft8756_lcdnoise_test(struct fts_test *tdata, bool *test_result) -{ - int ret = 0; - int i = 0; - bool tmp_result = false; - u8 old_mode = 0; - u8 status = 0; - int byte_num = 0; - int frame_num = 0; - int max = 0; - int *lcdnoise = NULL; - struct incell_threshold *thr = &tdata->ic.incell.thr; - - FTS_TEST_FUNC_ENTER(); - FTS_TEST_SAVE_INFO("\n============ Test Item: LCD Noise Test\n"); - memset(tdata->buffer, 0, tdata->buffer_length); - lcdnoise = tdata->buffer; - - ret = enter_factory_mode(); - if (ret < 0) { - FTS_TEST_SAVE_ERR("enter factory mode fail,ret=%d\n", ret); - goto test_err; - } - - ret = fts_test_read_reg(FACTORY_REG_DATA_SELECT, &old_mode); - if (ret < 0) { - FTS_TEST_SAVE_ERR("read reg06 fail\n"); - goto test_err; - } - - ret = fts_test_write_reg(FACTORY_REG_DATA_SELECT, 0x01); - if (ret < 0) { - FTS_TEST_SAVE_ERR("write 1 to reg06 fail\n"); - goto test_err; - } - - ret = fts_test_write_reg(FACTORY_REG_LINE_ADDR, 0xAD); - if (ret < 0) { - FTS_TEST_SAVE_ERR("write reg01 fail\n"); - goto test_err; - } - - frame_num = thr->basic.lcdnoise_frame; - ret = fts_test_write_reg(FACTORY_REG_LCD_NOISE_FRAME, frame_num / 4); - if (ret < 0) { - FTS_TEST_SAVE_INFO("write frame num fail\n"); - goto test_err; - } - - /* start test */ - ret = fts_test_write_reg(FACTORY_REG_LCD_NOISE_START, 0x01); - if (ret < 0) { - FTS_TEST_SAVE_INFO("start lcdnoise test fail\n"); - goto test_err; - } - - /* check test status */ - sys_delay(frame_num * FACTORY_TEST_DELAY / 2); - for (i = 0; i < FACTORY_TEST_RETRY; i++) { - status = 0xFF; - ret = fts_test_read_reg(FACTORY_REG_LCD_NOISE_TEST_STATE, &status); - if ((ret >= 0) && (TEST_RETVAL_AA == status)) { - break; - } else { - FTS_TEST_DBG("reg%x=%x,retry:%d\n", - FACTORY_REG_LCD_NOISE_TEST_STATE, status, i); - } - sys_delay(FACTORY_TEST_RETRY_DELAY); - } - if (i >= FACTORY_TEST_RETRY) { - FTS_TEST_SAVE_ERR("lcdnoise test timeout\n"); - goto test_err; - } - /* read lcdnoise */ - byte_num = tdata->node.node_num * 2; - ret = read_mass_data(FACTORY_REG_RAWDATA_ADDR, byte_num, lcdnoise); - if (ret < 0) { - FTS_TEST_SAVE_ERR("read rawdata fail\n"); - goto test_err; - } - - /* save */ - show_data(lcdnoise, false); - - /* compare */ - max = thr->basic.lcdnoise_coefficient * tdata->va_touch_thr * 32 / 100; - FTS_TEST_DBG("touch thr:%d, max:%d", tdata->va_touch_thr, max); - tmp_result = compare_data(lcdnoise, 0, max, 0, 0, false); - -test_err: - ret = fts_test_write_reg(FACTORY_REG_LCD_NOISE_START, 0x00); - if (ret < 0) { - FTS_TEST_SAVE_ERR("write 0 to reg11 fail\n"); - } - - ret = fts_test_write_reg(FACTORY_REG_DATA_SELECT, old_mode); - if (ret < 0) { - FTS_TEST_SAVE_ERR("restore reg06 fail\n"); - } - - ret = fts_test_write_reg(FACTORY_REG_LCD_NOISE_TEST_STATE, 0x03); - if (ret < 0) { - FTS_TEST_SAVE_ERR("write idle to lcdnoise test state fail\n"); - } - - if (tmp_result) { - *test_result = true; - FTS_TEST_SAVE_INFO("------ LCD Noise Test PASS\n"); - } else { - *test_result = false; - FTS_TEST_SAVE_INFO("------ LCD Noise Test NG\n"); - } - - /*save test data*/ - fts_test_save_data("LCD Noise Test", CODE_LCD_NOISE_TEST, - lcdnoise, 0, false, false, *test_result); - FTS_TEST_FUNC_EXIT(); - return ret; -} - -static int start_test_ft8756(void) -{ - int ret = 0; - struct fts_test *tdata = fts_ftest; - struct incell_testitem *test_item = &tdata->ic.incell.u.item; - bool temp_result = false; - bool test_result = true; - - FTS_TEST_FUNC_ENTER(); - FTS_TEST_INFO("test item:0x%x", fts_ftest->ic.incell.u.tmp); - - if (!tdata || !tdata->testresult || !tdata->buffer) { - FTS_TEST_ERROR("tdata is null"); - return -EINVAL; - } - - /* short test */ - if (true == test_item->short_test) { - ret = ft8756_short_test(tdata, &temp_result); - if ((ret < 0) || (false == temp_result)) { - test_result = false; - } - } - - /* open test */ - if (true == test_item->open_test) { - ret = ft8756_open_test(tdata, &temp_result); - if ((ret < 0) || (false == temp_result)) { - test_result = false; - } - } - - /* cb test */ - if (true == test_item->cb_test) { - ret = ft8756_cb_test(tdata, &temp_result); - if ((ret < 0) || (false == temp_result)) { - test_result = false; - } - } - - /* rawdata test */ - if (true == test_item->rawdata_test) { - ret = ft8756_rawdata_test(tdata, &temp_result); - if ((ret < 0) || (false == temp_result)) { - test_result = false; - } - } - - /* lcd noise test */ - if (true == test_item->lcdnoise_test) { - ret = ft8756_lcdnoise_test(tdata, &temp_result); - if ((ret < 0) || (false == temp_result)) { - test_result = false; - } - } - - return test_result; -} - -struct test_funcs test_func_ft8756 = { - .ctype = {0x15, 0x18}, - .hwtype = IC_HW_INCELL, - .key_num_total = 0, - .start_test = start_test_ft8756, -};