Initial commit: Linux kernel 4.19 for Unplugged OS

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

No files matched your search

@@ -0,0 +1,59 @@
#
# Touchscreen driver configuration
#
if TOUCHSCREEN_MTK_SYNAPTICS_I2C_RMI4
config SYNA_RMI4_FIRMWARE
string "Synaptics I2C touchscreen for Mediatek firmware"
config TOUCHSCREEN_MTK_SYNAPTICS_DSX_RMI4_DEV
tristate "Synaptics I2C touchscreen char device"
depends on TOUCHSCREEN_MTK_SYNAPTICS_I2C_RMI4
help
This enables support for character device channel for Synaptics RMI
touchscreens.
If unsure, say N.
To compile this driver as a module, choose M
config SYNA_RMI4_WARP_X_ON
bool "Synaptics I2C touchscreen for Mediatek package"
default n
help
Say Y here if you have Synaptics I2C touchscreen touch panel SYNA_RMI4_WARP_X_ON.
If unsure, say N.
To compile this dirver as a module, choose M here: the
module will be called.
config SYNA_RMI4_WARP_Y_ON
bool "Synaptics I2C touchscreen for Mediatek package"
default n
help
Say Y here if you have Synaptics I2C touchscreen touch panel SYNA_RMI4_WARP_Y_ON.
If unsure, say N.
To compile this dirver as a module, choose M here: the
module will be called.
config TOUCHSCREEN_MTK_SYNAPTICS_DSX_RMI4_FW_UPDATE
tristate "Synaptics I2C touchscreen firmware update"
depends on TOUCHSCREEN_MTK_SYNAPTICS_I2C_RMI4
help
This enables support for firmware update for Synaptics RMI
touchscreens.
If unsure, say N.
To compile this driver as a module, choose M
config SYNA_RMI4_AUTO_UPDATE
bool "Synaptics I2C touchscreen for Mediatek package"
default n
help
Say Y here if you have Synaptics touch panel SYNA_RMI4_AUTO_UPDATE.
If unsure, say N.
To compile this dirver as a module, choose M here: the
module will be called.
endif
@@ -0,0 +1,17 @@
# Linux driver folder
ccflags-y += -I$(srctree)/drivers/input/touchscreen/synaptics_i2c_rmi4/
ccflags-y += -I$(srctree)/drivers/input/touchscreen/
ccflags-y += -I$(srctree)/drivers/input/touchscreen/synaptics_i2c_rmi4/include/$(CONFIG_SYNA_RMI4_FIRMWARE)/
ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/
obj-$(CONFIG_TOUCHSCREEN_MTK_SYNAPTICS_I2C_RMI4) += synaptics_driver.o
obj-$(CONFIG_TOUCHSCREEN_MTK_SYNAPTICS_DSX_RMI4_DEV) += rmi_dev.o
obj-$(CONFIG_TOUCHSCREEN_MTK_SYNAPTICS_DSX_RMI4_FW_UPDATE) += rmi_fw_update.o
obj-y += tpd_control.o
obj-y += tpd_button.o
obj-y += tpd_debug.o
obj-y += tpd_default.o
obj-y += tpd_misc.o
obj-y += tpd_setting.o
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,535 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2012 Synaptics Incorporated.
*/
#ifndef _SYNAPTICS_DSX_RMI4_H_
#define _SYNAPTICS_DSX_RMI4_H_
#include "include/tpd_common_s7xxx.h"
#define SYNAPTICS_RMI4_DRIVER_VERSION "1.0"
#define PROXIMITY 0
#define PDT_PROPS (0X00EF)
#define PDT_START (0x00E9)
#define PDT_END (0x000A)
#define PDT_ENTRY_SIZE (0x0006)
#define PAGES_TO_SERVICE (10)
#define PAGE_SELECT_LEN (2)
#define SYNAPTICS_RMI4_F01 (0x01)
#define SYNAPTICS_RMI4_F11 (0x11)
#define SYNAPTICS_RMI4_F12 (0x12)
#define SYNAPTICS_RMI4_F1A (0x1a)
#define SYNAPTICS_RMI4_F34 (0x34)
#define SYNAPTICS_RMI4_F51 (0x51)
#define SYNAPTICS_RMI4_F54 (0x54)
#define SYNAPTICS_RMI4_PRODUCT_INFO_SIZE 2
#define SYNAPTICS_RMI4_PRODUCT_ID_LENGTH 10
#define MAX_NUMBER_OF_FINGERS 10
#define MAX_NUMBER_OF_BUTTONS 4
#define MAX_INTR_REGISTERS 4
#define MASK_16BIT 0xFFFF
#define MASK_8BIT 0xFF
#define MASK_7BIT 0x7F
#define MASK_6BIT 0x3F
#define MASK_5BIT 0x1F
#define MASK_4BIT 0x0F
#define MASK_3BIT 0x07
#define MASK_2BIT 0x03
#define MASK_1BIT 0x01
#define NO_0D_WHILE_2D 1
#define RPT_OBJ_TYPE (1 << 0)
#define RPT_X_LSB (1 << 1)
#define RPT_X_MSB (1 << 2)
#define RPT_Y_LSB (1 << 3)
#define RPT_Y_MSB (1 << 4)
#define RPT_Z (1 << 5)
#define RPT_WX (1 << 6)
#define RPT_WY (1 << 7)
#define F12_RPT_DEFAULT (RPT_OBJ_TYPE | RPT_X_LSB | RPT_Y_LSB | RPT_Y_MSB)
#define F12_RPT (F12_RPT_DEFAULT | RPT_WX | RPT_WY)
#if PROXIMITY
#define HOVER_Z_MAX 255
#define FINGER_HOVER (1 << 0)
#define AIR_SWIPE (1 << 1)
#define LARGE_OBJ (1 << 2)
#define HOVER_PINCH (1 << 3)
#define NO_PROXIMITY_ON_TOUCH (1 << 5)
#define PROXIMITY_ENABLE (FINGER_HOVER | NO_PROXIMITY_ON_TOUCH)
#endif
#define EXP_FN_DET_INTERVAL 1000 /* ms */
#define POLLING_PERIOD 1 /* ms */
#define SYN_I2C_RETRY_TIMES 10
#define MAX_TOUCH_MAJOR 15
#define F01_STD_QUERY_LEN 21
#define F11_STD_QUERY_LEN 9
#define F11_STD_CTRL_LEN 10
#define F11_STD_DATA_LEN 12
#define NORMAL_OPERATION (0 << 0)
#define SENSOR_SLEEP (1 << 0)
#define NO_SLEEP_OFF (0 << 3)
#define NO_SLEEP_ON (1 << 3)
enum exp_fn {
RMI_DEV = 0,
RMI_F34,
RMI_F54,
RMI_FW_UPDATER,
RMI_LAST,
};
struct synaptics_rmi4_f12_query_5 {
union {
struct {
unsigned char size_of_query6;
struct {
unsigned char ctrl0_is_present:1;
unsigned char ctrl1_is_present:1;
unsigned char ctrl2_is_present:1;
unsigned char ctrl3_is_present:1;
unsigned char ctrl4_is_present:1;
unsigned char ctrl5_is_present:1;
unsigned char ctrl6_is_present:1;
unsigned char ctrl7_is_present:1;
} __packed;
struct {
unsigned char ctrl8_is_present:1;
unsigned char ctrl9_is_present:1;
unsigned char ctrl10_is_present:1;
unsigned char ctrl11_is_present:1;
unsigned char ctrl12_is_present:1;
unsigned char ctrl13_is_present:1;
unsigned char ctrl14_is_present:1;
unsigned char ctrl15_is_present:1;
} __packed;
struct {
unsigned char ctrl16_is_present:1;
unsigned char ctrl17_is_present:1;
unsigned char ctrl18_is_present:1;
unsigned char ctrl19_is_present:1;
unsigned char ctrl20_is_present:1;
unsigned char ctrl21_is_present:1;
unsigned char ctrl22_is_present:1;
unsigned char ctrl23_is_present:1;
} __packed;
};
unsigned char data[4];
};
};
struct synaptics_rmi4_f12_query_8 {
union {
struct {
unsigned char size_of_query9;
struct {
unsigned char data0_is_present:1;
unsigned char data1_is_present:1;
unsigned char data2_is_present:1;
unsigned char data3_is_present:1;
unsigned char data4_is_present:1;
unsigned char data5_is_present:1;
unsigned char data6_is_present:1;
unsigned char data7_is_present:1;
} __packed;
};
unsigned char data[2];
};
};
struct synaptics_rmi4_f12_ctrl_8 {
union {
struct {
unsigned char max_x_coord_lsb;
unsigned char max_x_coord_msb;
unsigned char max_y_coord_lsb;
unsigned char max_y_coord_msb;
unsigned char rx_pitch_lsb;
unsigned char rx_pitch_msb;
unsigned char tx_pitch_lsb;
unsigned char tx_pitch_msb;
unsigned char low_rx_clip;
unsigned char high_rx_clip;
unsigned char low_tx_clip;
unsigned char high_tx_clip;
unsigned char num_of_rx;
unsigned char num_of_tx;
};
unsigned char data[14];
};
};
struct synaptics_rmi4_f12_ctrl_23 {
union {
struct {
unsigned char obj_type_enable;
unsigned char max_reported_objects;
};
unsigned char data[2];
};
};
struct synaptics_rmi4_f12_finger_data {
union {
struct {
unsigned char object_type_and_status;
unsigned char x_lsb;
unsigned char x_msb;
unsigned char y_lsb;
unsigned char y_msb;
unsigned char z;
unsigned char wx;
unsigned char wy;
};
unsigned char data[8];
};
};
struct synaptics_rmi4_f1a_query {
union {
struct {
unsigned char max_button_count:3;
unsigned char reserved:5;
unsigned char has_general_control:1;
unsigned char has_interrupt_enable:1;
unsigned char has_multibutton_select:1;
unsigned char has_tx_rx_map:1;
unsigned char has_perbutton_threshold:1;
unsigned char has_release_threshold:1;
unsigned char has_strongestbtn_hysteresis:1;
unsigned char has_filter_strength:1;
} __packed;
unsigned char data[2];
};
};
struct synaptics_rmi4_f1a_control_0 {
union {
struct {
unsigned char multibutton_report:2;
unsigned char filter_mode:2;
unsigned char reserved:4;
} __packed;
unsigned char data[1];
};
};
struct synaptics_rmi4_f1a_control_3_4 {
unsigned char transmitterbutton;
unsigned char receiverbutton;
};
struct synaptics_rmi4_f1a_control {
struct synaptics_rmi4_f1a_control_0 general_control;
unsigned char *button_int_enable;
unsigned char *multi_button;
struct synaptics_rmi4_f1a_control_3_4 *electrode_map;
unsigned char *button_threshold;
unsigned char button_release_threshold;
unsigned char strongest_button_hysteresis;
unsigned char filter_strength;
};
struct synaptics_rmi4_f1a_handle {
int button_bitmask_size;
unsigned char button_count;
unsigned char valid_button_count;
unsigned char *button_data_buffer;
unsigned char *button_map;
struct synaptics_rmi4_f1a_query button_query;
struct synaptics_rmi4_f1a_control button_control;
};
#if PROXIMITY
struct synaptics_rmi4_f51_query {
union {
struct {
unsigned char query_register_count;
unsigned char data_register_count;
unsigned char control_register_count;
unsigned char command_register_count;
};
unsigned char data[4];
};
};
struct synaptics_rmi4_f51_data {
union {
struct {
unsigned char finger_hover_det:1;
unsigned char air_swipe_det:1;
unsigned char large_obj_det:1;
unsigned char f1a_data0_b3:1;
unsigned char hover_pinch_det:1;
unsigned char f1a_data0_b5__7:3;
unsigned char hover_finger_x_4__11;
unsigned char hover_finger_y_4__11;
unsigned char hover_finger_xy_0__3;
unsigned char hover_finger_z;
unsigned char f1a_data2_b0__6:7;
unsigned char hover_pinch_dir:1;
unsigned char air_swipe_dir_0:1;
unsigned char air_swipe_dir_1:1;
unsigned char f1a_data3_b2__5:4;
unsigned char large_obj_act:2;
} __packed;
unsigned char data[7];
};
};
struct synaptics_rmi4_f51_handle {
unsigned short proximity_enables_addr;
struct synaptics_rmi4_data *rmi4_data;
};
#endif
struct synaptics_rmi4_exp_fn {
enum exp_fn fn_type;
bool inserted;
int (*func_init)(struct i2c_client *client);
void (*func_remove)(struct i2c_client *client);
void (*func_attn)(struct i2c_client *client, unsigned char intr_mask);
struct list_head link;
};
/*
* struct synaptics_rmi4_fn_desc - function descriptor fields in PDT
* @query_base_addr: base address for query registers
* @cmd_base_addr: base address for command registers
* @ctrl_base_addr: base address for control registers
* @data_base_addr: base address for data registers
* @intr_src_count: number of interrupt sources
* @fn_number: function number
*/
struct synaptics_rmi4_fn_desc {
unsigned char query_base_addr;
unsigned char cmd_base_addr;
unsigned char ctrl_base_addr;
unsigned char data_base_addr;
unsigned char intr_src_count;
unsigned char fn_number;
};
/*
* synaptics_rmi4_fn_full_addr - full 16-bit base addresses
* @query_base: 16-bit base address for query registers
* @cmd_base: 16-bit base address for data registers
* @ctrl_base: 16-bit base address for command registers
* @data_base: 16-bit base address for control registers
*/
struct synaptics_rmi4_fn_full_addr {
unsigned short query_base;
unsigned short cmd_base;
unsigned short ctrl_base;
unsigned short data_base;
};
/*
* struct synaptics_rmi4_fn - function handler data structure
* @fn_number: function number
* @num_of_data_sources: number of data sources
* @num_of_data_points: maximum number of fingers supported
* @size_of_data_register_block: data register block size
* @data1_offset: offset to data1 register from data base address
* @intr_reg_num: index to associated interrupt register
* @intr_mask: interrupt mask
* @full_addr: full 16-bit base addresses of function registers
* @link: linked list for function handlers
* @data_size: size of private data
* @data: pointer to private data
*/
struct synaptics_rmi4_fn {
unsigned char fn_number;
unsigned char num_of_data_sources;
unsigned char num_of_data_points;
unsigned char size_of_data_register_block;
unsigned char data1_offset;
unsigned char intr_reg_num;
unsigned char intr_mask;
struct synaptics_rmi4_fn_full_addr full_addr;
struct list_head link;
int data_size;
void *data;
};
/*
* struct synaptics_rmi4_device_info - device information
* @version_major: rmi protocol major version number
* @version_minor: rmi protocol minor version number
* @manufacturer_id: manufacturer id
* @product_props: product properties information
* @product_info: product info array
* @date_code: device manufacture date
* @tester_id: tester id array
* @serial_number: device serial number
* @product_id_string: device product id
* @support_fn_list: linked list for function handlers
*/
struct synaptics_rmi4_device_info {
unsigned int version_major;
unsigned int version_minor;
unsigned char manufacturer_id;
unsigned char product_props;
unsigned char product_info[2];
unsigned char date_code[3];
unsigned short tester_id;
unsigned short serial_number;
unsigned char product_id_string[11];
struct list_head support_fn_list;
};
struct synaptics_rmi4_f01_device_status {
union {
struct {
unsigned char status_code:4;
unsigned char reserved:2;
unsigned char flash_prog:1;
unsigned char unconfigured:1;
} __packed;
unsigned char data[1];
};
};
/*
* struct synaptics_rmi4_data - rmi4 device instance data
* @i2c_client: pointer to associated i2c client
* @input_dev: pointer to associated input device
* @board: constant pointer to platform data
* @rmi4_mod_info: device information
* @regulator: pointer to associated regulator
* @rmi4_io_ctrl_mutex: mutex for i2c i/o control
* @det_work: work thread instance for expansion function detection
* @det_workqueue: pointer to work queue for work thread instance
* @early_suspend: instance to support early suspend power management
* @current_page: current page in sensor to access
* @button_0d_enabled: flag for 0d button support
* @full_pm_cycle: flag for full power management cycle in early suspend stage
* @num_of_intr_regs: number of interrupt registers
* @f01_query_base_addr: query base address for f01
* @f01_cmd_base_addr: command base address for f01
* @f01_ctrl_base_addr: control base address for f01
* @f01_data_base_addr: data base address for f01
* @irq: attention interrupt
* @sensor_max_x: sensor maximum x value
* @sensor_max_y: sensor maximum y value
* @irq_enabled: flag for indicating interrupt enable status
* @touch_stopped: flag to stop interrupt thread processing
* @fingers_on_2d: flag to indicate presence of fingers in 2d area
* @sensor_sleep: flag to indicate sleep state of sensor
* @wait: wait queue for touch data polling in interrupt thread
* @i2c_read: pointer to i2c read function
* @i2c_write: pointer to i2c write function
* @irq_enable: pointer to irq enable function
*/
struct synaptics_rmi4_data {
struct i2c_client *i2c_client;
struct input_dev *input_dev;
const struct synaptics_dsx_platform_data *board;
struct synaptics_rmi4_device_info rmi4_mod_info;
struct regulator *regulator;
struct mutex rmi4_io_ctrl_mutex;
/* struct delayed_work det_work; */
struct work_struct work;
struct workqueue_struct *det_workqueue;
struct workqueue_struct *workqueue;
/* struct early_suspend early_suspend; */
unsigned char current_page;
unsigned char button_0d_enabled;
unsigned char full_pm_cycle;
unsigned char num_of_rx;
unsigned char num_of_tx;
unsigned char intr_mask[MAX_INTR_REGISTERS];
unsigned short num_of_intr_regs;
unsigned short f01_query_base_addr;
unsigned short f01_cmd_base_addr;
unsigned short f01_ctrl_base_addr;
unsigned short f01_data_base_addr;
int irq;
int sensor_max_x;
int sensor_max_y;
bool irq_enabled;
bool touch_stopped;
bool fingers_on_2d;
bool sensor_sleep;
wait_queue_head_t wait;
int (*i2c_read)(struct synaptics_rmi4_data *pdata, unsigned short addr,
unsigned char *data, unsigned short length);
int (*i2c_write)(struct synaptics_rmi4_data *pdata, unsigned short addr,
unsigned char *data, unsigned short length);
int (*irq_enable)(struct synaptics_rmi4_data *rmi4_data, bool enable);
int (*reset_device)(struct synaptics_rmi4_data *rmi4_data);
};
struct synaptics_rmi4_exp_fn_ptr {
int (*read)(struct synaptics_rmi4_data *rmi4_data, unsigned short addr,
unsigned char *data, unsigned short length);
int (*write)(struct synaptics_rmi4_data *rmi4_data, unsigned short addr,
unsigned char *data, unsigned short length);
int (*enable)(struct synaptics_rmi4_data *rmi4_data, bool enable);
};
void synaptics_rmi4_new_function(enum exp_fn fn_type, bool insert,
int (*func_init)(struct i2c_client *client),
void (*func_remove)(struct i2c_client *client),
void (*func_attn)(struct i2c_client *client,
unsigned char intr_mask));
static inline ssize_t synaptics_rmi4_show_error(struct device *dev,
struct device_attribute *attr, char *buf)
{
return -EPERM;
}
static inline ssize_t synaptics_rmi4_store_error(struct device *dev,
struct device_attribute *attr, const char *buf,
size_t count)
{
return -EPERM;
}
static inline void batohs(unsigned short *dest, unsigned char *src)
{
*dest = src[1] * 0x100 + src[0];
}
static inline void hstoba(unsigned char *dest, unsigned short src)
{
dest[0] = src % 0x100;
dest[1] = src / 0x100;
}
extern struct tpd_device *tpd;
extern struct kobject *properties_kobj_synap;
extern int tpd_i2c_read_data(struct i2c_client *client,
unsigned short addr, unsigned char *data,
unsigned short length);
extern int tpd_i2c_write_data(struct i2c_client *client,
unsigned short addr, unsigned char *data,
unsigned short length);
extern int synaptics_fw_updater(unsigned char *fw_data);
#ifdef VELOCITY_CUSTOM
extern int tpd_v_magnify_x;
extern int tpd_v_magnify_y;
#endif
#endif
@@ -0,0 +1,34 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2012 Synaptics Incorporated.
*/
#ifndef TOUCHPANEL_H__
#define TOUCHPANEL_H__
/* Pre-defined definition */
/* Register */
#define FD_ADDR_MAX 0xE9
#define FD_ADDR_MIN 0xDD
#define FD_BYTE_COUNT 6
/*all custom setting has removed to *.dtsi and {project}_defconfig*/
#ifdef CONFIG_SYNA_RMI4_AUTO_UPDATE
#define TPD_UPDATE_FIRMWARE
#endif
#define VELOCITY_CUSTOM
#define TPD_VELOCITY_CUSTOM_X 15
#define TPD_VELOCITY_CUSTOM_Y 15
/* #define TPD_HAVE_CALIBRATION */
/* #define TPD_CALIBRATION_MATRIX {2680,0,0,0,2760,0,0,0}; */
/* #define TPD_WARP_START */
/* #define TPD_WARP_END */
/* #define TPD_RESET_ISSUE_WORKAROUND */
/* #define TPD_MAX_RESET_COUNT 3 */
/* #define TPD_WARP_Y(y) ( TPD_Y_RES - 1 - y ) */
/* #define TPD_WARP_X(x) ( x ) */
#endif /* TOUCHPANEL_H__ */
@@ -0,0 +1,55 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#undef TRACE_SYSTEM
#define TRACE_SYSTEM met_touch
#if !defined(__TRACE_MET_FTRACE_TOUCH_H__) || defined(TRACE_HEADER_MULTI_READ)
#define __TRACE_MET_FTRACE_TOUCH_H__
#include <linux/tracepoint.h>
/*
* Tracepoint for MET_touch
*/
TRACE_EVENT(MET_touch,
TP_PROTO(char *touch_type, long tsec, long tusec,
char *mode, int value),
TP_ARGS(touch_type, tsec, tusec, mode, value),
TP_STRUCT__entry(
__array(char, _touch_type, 16)
__field(long, _tsec)
__field(long, _tusec)
__array(char, _mode, 16)
__field(int, _value)
),
TP_fast_assign(
memcpy(__entry->_touch_type, touch_type, 16);
__entry->_tsec = tsec;
__entry->_tusec = tusec;
memcpy(__entry->_mode, mode, 16);
__entry->_value = value;
),
TP_printk("%s,%ld.%06ld,%s,%x",
__entry->_touch_type,
__entry->_tsec,
__entry->_tusec,
__entry->_mode,
__entry->_value
)
);
#endif /* __TRACE_MET_FTRACE_TOUCH_H__ */
/* This part must be outside protection */
#undef TRACE_INCLUDE_PATH
#undef linux
#define TRACE_INCLUDE_PATH .
#define TRACE_INCLUDE_FILE met_ftrace_touch
#include <trace/define_trace.h>
@@ -0,0 +1,751 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2012 Synaptics Incorporated.
*/
#include <linux/cdev.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#ifdef CONFIG_HAS_EARLYSUSPEND
#include <linux/earlysuspend.h>
#endif
/* #include <linux/input/synaptics_dsx.h> */
#include "include/synaptics_dsx_rmi4_i2c.h"
#include "tpd.h"
#define SYN_I2C_RETRY_TIMES 10
#define CHAR_DEVICE_NAME "rmi"
#define DEVICE_CLASS_NAME "rmidev"
#define DEV_NUMBER 1
#define REG_ADDR_LIMIT 0xFFFF
struct kobject *properties_kobj_rmidev;
static ssize_t rmidev_sysfs_open_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count);
static ssize_t rmidev_sysfs_release_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count);
static ssize_t rmidev_sysfs_address_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count);
static ssize_t rmidev_sysfs_length_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count);
static ssize_t rmidev_sysfs_data_show(struct device *dev,
struct device_attribute *attr, char *buf);
static ssize_t rmidev_sysfs_data_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count);
static ssize_t rmidev_sysfs_attn_show(struct device *dev,
struct device_attribute *attr, char *buf);
static ssize_t rmidev_sysfs_attn_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count);
struct rmidev_handle {
dev_t dev_no;
unsigned short address;
unsigned int length;
struct device dev;
struct synaptics_rmi4_data *rmi4_data;
struct synaptics_rmi4_exp_fn_ptr *fn_ptr;
struct kobject *sysfs_dir;
void *data;
};
struct rmidev_data {
int ref_count;
struct cdev main_dev;
struct class *device_class;
struct mutex file_mutex;
struct rmidev_handle *rmi_dev;
};
static struct device_attribute attrs[] = {
__ATTR(open, (0644), synaptics_rmi4_show_error,
rmidev_sysfs_open_store),
__ATTR(release, (0644), synaptics_rmi4_show_error,
rmidev_sysfs_release_store),
__ATTR(address, (0644), synaptics_rmi4_show_error,
rmidev_sysfs_address_store),
__ATTR(length, (0644), synaptics_rmi4_show_error,
rmidev_sysfs_length_store),
__ATTR(data, (0644), rmidev_sysfs_data_show,
rmidev_sysfs_data_store),
__ATTR(attn, (0644), rmidev_sysfs_attn_show,
rmidev_sysfs_attn_store),
};
static int rmidev_major_num;
static struct class *rmidev_device_class;
static struct rmidev_handle *rmidev;
static struct completion remove_complete;
static ssize_t rmidev_sysfs_open_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
unsigned int input;
if (kstrtoint(buf, 10, &input))
return -EINVAL;
if (input != 1)
return -EINVAL;
rmidev->fn_ptr->enable(rmidev->rmi4_data, false);
dev_dbg(&rmidev->rmi4_data->i2c_client->dev,
"%s: Attention interrupt disabled\n", __func__);
return count;
}
static ssize_t rmidev_sysfs_release_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
unsigned int input;
if (kstrtoint(buf, 10, &input))
return -EINVAL;
if (input != 1)
return -EINVAL;
rmidev->fn_ptr->enable(rmidev->rmi4_data, true);
dev_dbg(&rmidev->rmi4_data->i2c_client->dev,
"%s: Attention interrupt enabled\n", __func__);
return count;
}
static ssize_t rmidev_sysfs_address_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
unsigned int input;
if (kstrtoint(buf, 10, &input))
return -EINVAL;
if (input > REG_ADDR_LIMIT)
return -EINVAL;
rmidev->address = (unsigned short)input;
return count;
}
static ssize_t rmidev_sysfs_length_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
unsigned int input;
if (kstrtoint(buf, 10, &input))
return -EINVAL;
if (input > REG_ADDR_LIMIT)
return -EINVAL;
rmidev->length = input;
return count;
}
static ssize_t rmidev_sysfs_data_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int retval;
unsigned int data_length = rmidev->length;
if (data_length > (REG_ADDR_LIMIT - rmidev->address))
data_length = REG_ADDR_LIMIT - rmidev->address;
if (data_length) {
retval =
rmidev->fn_ptr->read(rmidev->rmi4_data, rmidev->address,
(unsigned char *)buf, data_length);
if (retval < 0) {
dev_info(&rmidev->rmi4_data->i2c_client->dev,
"%s: Failed to read data\n", __func__);
return retval;
}
} else {
return -EINVAL;
}
return data_length;
}
static ssize_t rmidev_sysfs_data_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
int retval;
unsigned int data_length = rmidev->length;
if (data_length > (REG_ADDR_LIMIT - rmidev->address))
data_length = REG_ADDR_LIMIT - rmidev->address;
if (data_length) {
retval = rmidev->fn_ptr->write(
rmidev->rmi4_data, rmidev->address,
(unsigned char *)buf, data_length);
if (retval < 0) {
dev_info(&rmidev->rmi4_data->i2c_client->dev,
"%s: Failed to write data\n", __func__);
return retval;
}
} else {
return -EINVAL;
}
return data_length;
}
static ssize_t rmidev_sysfs_attn_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int attn = 0 /*gpio_get_value(tpd_int_gpio_number)*/;
return sprintf(buf, "%d %d\n", IRQF_TRIGGER_FALLING, attn);
}
static ssize_t rmidev_sysfs_attn_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
return 0;
}
/*
* rmidev_llseek - used to set up register address
*
* @filp: file structure for seek
* @off: offset
* if whence == SEEK_SET,
* high 16 bits: page address
* low 16 bits: register address
* if whence == SEEK_CUR,
* offset from current position
* if whence == SEEK_END,
* offset from end position (0xFFFF)
* @whence: SEEK_SET, SEEK_CUR, or SEEK_END
*/
static loff_t rmidev_llseek(struct file *filp, loff_t off, int whence)
{
loff_t newpos;
struct rmidev_data *dev_data = filp->private_data;
if (IS_ERR(dev_data)) {
pr_info("%s: Pointer of char device data is invalid", __func__);
return -EBADF;
}
mutex_lock(&(dev_data->file_mutex));
switch (whence) {
case SEEK_SET:
newpos = off;
break;
case SEEK_CUR:
newpos = filp->f_pos + off;
break;
case SEEK_END:
newpos = REG_ADDR_LIMIT + off;
break;
default:
newpos = -EINVAL;
goto clean_up;
}
if (newpos < 0 || newpos > REG_ADDR_LIMIT) {
dev_info(&rmidev->rmi4_data->i2c_client->dev,
"%s: New position 0x%04x is invalid\n", __func__,
(unsigned int)newpos);
newpos = -EINVAL;
goto clean_up;
}
filp->f_pos = newpos;
clean_up:
mutex_unlock(&(dev_data->file_mutex));
return newpos;
}
/*
* rmidev_read: - use to read data from rmi device
*
* @filp: file structure for read
* @buf: user space buffer pointer
* @count: number of bytes to read
* @f_pos: offset (starting register address)
*/
static ssize_t rmidev_read(struct file *filp, char __user *buf, size_t count,
loff_t *f_pos)
{
ssize_t retval;
unsigned char tmpbuf[count + 1];
struct rmidev_data *dev_data = filp->private_data;
if (IS_ERR(dev_data)) {
pr_info("%s: Pointer of char device data is invalid", __func__);
return -EBADF;
}
if (count == 0)
return 0;
if (count > (REG_ADDR_LIMIT - *f_pos))
count = REG_ADDR_LIMIT - *f_pos;
mutex_lock(&(dev_data->file_mutex));
retval = rmidev->fn_ptr->read(rmidev->rmi4_data, *f_pos, tmpbuf, count);
if (retval < 0)
goto clean_up;
if (copy_to_user(buf, tmpbuf, count))
retval = -EFAULT;
else
*f_pos += retval;
clean_up:
mutex_unlock(&(dev_data->file_mutex));
return retval;
}
/*
* rmidev_write: - used to write data to rmi device
*
* @filep: file structure for write
* @buf: user space buffer pointer
* @count: number of bytes to write
* @f_pos: offset (starting register address)
*/
static ssize_t rmidev_write(struct file *filp, const char __user *buf,
size_t count, loff_t *f_pos)
{
ssize_t retval;
unsigned char tmpbuf[count + 1];
struct rmidev_data *dev_data = filp->private_data;
if (IS_ERR(dev_data)) {
pr_info("%s: Pointer of char device data is invalid", __func__);
return -EBADF;
}
if (count == 0)
return 0;
if (count > (REG_ADDR_LIMIT - *f_pos))
count = REG_ADDR_LIMIT - *f_pos;
if (copy_from_user(tmpbuf, buf, count))
return -EFAULT;
mutex_lock(&(dev_data->file_mutex));
retval =
rmidev->fn_ptr->write(rmidev->rmi4_data, *f_pos, tmpbuf, count);
if (retval >= 0)
*f_pos += retval;
mutex_unlock(&(dev_data->file_mutex));
return retval;
}
/*
* rmidev_open: enable access to rmi device
* @inp: inode struture
* @filp: file structure
*/
static int rmidev_open(struct inode *inp, struct file *filp)
{
int retval = 0;
struct rmidev_data *dev_data =
container_of(inp->i_cdev, struct rmidev_data, main_dev);
if (!dev_data)
return -EACCES;
filp->private_data = dev_data;
mutex_lock(&(dev_data->file_mutex));
rmidev->fn_ptr->enable(rmidev->rmi4_data, false);
dev_dbg(&rmidev->rmi4_data->i2c_client->dev,
"%s: Attention interrupt disabled\n", __func__);
if (dev_data->ref_count < 1)
dev_data->ref_count++;
else
retval = -EACCES;
mutex_unlock(&(dev_data->file_mutex));
return retval;
}
/*
* rmidev_release: - release access to rmi device
* @inp: inode structure
* @filp: file structure
*/
static int rmidev_release(struct inode *inp, struct file *filp)
{
struct rmidev_data *dev_data =
container_of(inp->i_cdev, struct rmidev_data, main_dev);
if (!dev_data)
return -EACCES;
mutex_lock(&(dev_data->file_mutex));
dev_data->ref_count--;
if (dev_data->ref_count < 0)
dev_data->ref_count = 0;
rmidev->fn_ptr->enable(rmidev->rmi4_data, true);
dev_dbg(&rmidev->rmi4_data->i2c_client->dev,
"%s: Attention interrupt enabled\n", __func__);
mutex_unlock(&(dev_data->file_mutex));
return 0;
}
static const struct file_operations rmidev_fops = {
.owner = THIS_MODULE,
.llseek = rmidev_llseek,
.read = rmidev_read,
.write = rmidev_write,
.open = rmidev_open,
.release = rmidev_release,
};
static void rmidev_device_cleanup(struct rmidev_data *dev_data)
{
dev_t devno;
if (dev_data) {
devno = dev_data->main_dev.dev;
if (dev_data->device_class)
device_destroy(dev_data->device_class, devno);
cdev_del(&dev_data->main_dev);
unregister_chrdev_region(devno, 1);
dev_dbg(&rmidev->rmi4_data->i2c_client->dev,
"%s: rmidev device removed\n", __func__);
}
}
static char *rmi_char_devnode(struct device *dev, umode_t *mode)
{
if (!mode)
return NULL;
*mode = (0666);
return kasprintf(GFP_KERNEL, "rmi/%s", dev_name(dev));
}
static int rmidev_create_device_class(void)
{
rmidev_device_class = class_create(THIS_MODULE, DEVICE_CLASS_NAME);
if (IS_ERR(rmidev_device_class)) {
pr_info("%s: Failed to create /dev/%s\n", __func__,
CHAR_DEVICE_NAME);
return -ENODEV;
}
rmidev_device_class->devnode = rmi_char_devnode;
return 0;
}
static int synaptics_rmi4_i2c_read(struct synaptics_rmi4_data *rmi4_data,
unsigned short addr, unsigned char *data,
unsigned short length)
{
return tpd_i2c_read_data(rmi4_data->i2c_client, addr, data, length);
}
static int synaptics_rmi4_i2c_write(struct synaptics_rmi4_data *rmi4_data,
unsigned short addr, unsigned char *data,
unsigned short length)
{
return tpd_i2c_write_data(rmi4_data->i2c_client, addr, data, length);
}
static int synaptics_rmi4_irq_enable(struct synaptics_rmi4_data *rmi4_data,
bool enable)
{
int retval = 0;
unsigned char intr_status;
/* const struct synaptics_dsx_platform_data *platform_data = */
/* rmi4_data->i2c_client->dev.platform_data; */
if (enable) {
if (rmi4_data->irq_enabled)
return retval;
/* Clear interrupts first */
retval = synaptics_rmi4_i2c_read(
rmi4_data, rmi4_data->f01_data_base_addr + 1,
&intr_status, rmi4_data->num_of_intr_regs);
if (retval < 0)
return retval;
rmi4_data->irq_enabled = true;
} else {
if (rmi4_data->irq_enabled) {
disable_irq(rmi4_data->irq);
free_irq(rmi4_data->irq, rmi4_data);
rmi4_data->irq_enabled = false;
}
}
return retval;
}
static int rmidev_init_device(struct i2c_client *client)
{
int retval;
dev_t dev_no;
unsigned char attr_count;
struct rmidev_data *dev_data;
struct device *device_ptr;
TPD_DMESG("%s:enter\n", __func__);
rmidev = kzalloc(sizeof(*rmidev), GFP_KERNEL);
if (!rmidev) {
retval = -ENOMEM;
goto err_rmidev;
}
rmidev->rmi4_data =
kzalloc(sizeof(struct synaptics_rmi4_data), GFP_KERNEL);
if (!rmidev->rmi4_data) {
/*dev_info(&client->dev, "%s: Failed to alloc mem for*/
/* rmi4_data\n", __func__);*/
retval = -ENOMEM;
goto err_fn_ptr;
}
rmidev->fn_ptr = kzalloc(sizeof(*(rmidev->fn_ptr)), GFP_KERNEL);
if (!rmidev) {
retval = -ENOMEM;
goto exit_free_rmi4;
}
rmidev->rmi4_data->input_dev = tpd->dev;
rmidev->rmi4_data->i2c_client = client;
rmidev->fn_ptr->read = synaptics_rmi4_i2c_read;
rmidev->fn_ptr->write = synaptics_rmi4_i2c_write;
rmidev->fn_ptr->enable = synaptics_rmi4_irq_enable;
mutex_init(&(rmidev->rmi4_data->rmi4_io_ctrl_mutex));
retval = rmidev_create_device_class();
if (retval < 0) {
dev_info(&client->dev, "%s: Failed to create device class\n",
__func__);
goto err_device_class;
}
TPD_DMESG("%s:after create device class\n", __func__);
if (rmidev_major_num) {
dev_no = MKDEV(rmidev_major_num, DEV_NUMBER);
retval = register_chrdev_region(dev_no, 1, CHAR_DEVICE_NAME);
} else {
retval = alloc_chrdev_region(&dev_no, 0, 1, CHAR_DEVICE_NAME);
if (retval < 0) {
dev_info(&client->dev,
"%s: Failed to allocate char device region\n",
__func__);
goto err_device_region;
}
rmidev_major_num = MAJOR(dev_no);
dev_dbg(&client->dev, "%s: Major number of rmidev = %d\n",
__func__, rmidev_major_num);
}
dev_data = kzalloc(sizeof(*dev_data), GFP_KERNEL);
if (!dev_data) {
retval = -ENOMEM;
goto err_dev_data;
}
mutex_init(&dev_data->file_mutex);
dev_data->rmi_dev = rmidev;
rmidev->data = dev_data;
cdev_init(&dev_data->main_dev, &rmidev_fops);
retval = cdev_add(&dev_data->main_dev, dev_no, 1);
if (retval < 0) {
dev_info(&client->dev, "%s: Failed to add rmi char device\n",
__func__);
goto err_char_device;
}
dev_set_name(&rmidev->dev, "rmidev%d", MINOR(dev_no));
dev_data->device_class = rmidev_device_class;
device_ptr = device_create(dev_data->device_class, NULL, dev_no, NULL,
CHAR_DEVICE_NAME "%d", MINOR(dev_no));
TPD_DMESG("%s:after devicecreate\n", __func__);
if (IS_ERR(device_ptr)) {
dev_info(&client->dev, "%s: Failed to create rmi char device\n",
__func__);
retval = -ENODEV;
goto err_char_device;
}
properties_kobj_rmidev =
kobject_create_and_add("rmidev", properties_kobj_synap);
if (!properties_kobj_rmidev) {
dev_info(&rmidev->rmi4_data->i2c_client->dev,
"%s: Failed to create sysfs directory\n", __func__);
goto err_sysfs_dir;
}
for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) {
/* retval = sysfs_create_file(rmidev->sysfs_dir,*/
/* &attrs[attr_count].attr); */
retval = sysfs_create_file(properties_kobj_rmidev,
&attrs[attr_count].attr);
if (retval < 0) {
dev_info(&rmidev->rmi4_data->input_dev->dev,
"%s: Failed to create sysfs attributes\n",
__func__);
retval = -ENODEV;
goto err_sysfs_attrs;
}
}
return 0;
err_sysfs_attrs:
for (attr_count--; attr_count >= 0; attr_count--)
sysfs_remove_file(properties_kobj_rmidev,
&attrs[attr_count].attr);
kobject_put(properties_kobj_rmidev);
err_sysfs_dir:
err_char_device:
rmidev_device_cleanup(dev_data);
kfree(dev_data);
err_dev_data:
unregister_chrdev_region(dev_no, 1);
err_device_region:
class_destroy(rmidev_device_class);
err_device_class:
kfree(rmidev->rmi4_data);
exit_free_rmi4:
kfree(rmidev);
err_fn_ptr:
kfree(rmidev);
err_rmidev:
return retval;
}
static void rmidev_remove_device(struct i2c_client *client)
{
unsigned char attr_count;
struct rmidev_data *dev_data;
if (!rmidev)
return;
for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++)
sysfs_remove_file(rmidev->sysfs_dir, &attrs[attr_count].attr);
kobject_put(rmidev->sysfs_dir);
dev_data = rmidev->data;
if (dev_data) {
rmidev_device_cleanup(dev_data);
kfree(dev_data);
}
unregister_chrdev_region(rmidev->dev_no, 1);
class_destroy(rmidev_device_class);
kfree(rmidev->fn_ptr);
kfree(rmidev);
complete(&remove_complete);
}
static int __init rmidev_module_init(void)
{
synaptics_rmi4_new_function(RMI_DEV, true, rmidev_init_device,
rmidev_remove_device, NULL);
return 0;
}
static void __exit rmidev_module_exit(void)
{
init_completion(&remove_complete);
synaptics_rmi4_new_function(RMI_DEV, false, rmidev_init_device,
rmidev_remove_device, NULL);
wait_for_completion(&remove_complete);
}
module_init(rmidev_module_init);
module_exit(rmidev_module_exit);
MODULE_AUTHOR("Synaptics, Inc.");
MODULE_DESCRIPTION("RMI4 RMI_Dev Module");
MODULE_LICENSE("GPL");
MODULE_VERSION(SYNAPTICS_RMI4_DRIVER_VERSION);
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,182 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#ifndef __TPD_H
#define __TPD_H
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/input.h>
#include <linux/interrupt.h>
#include <linux/time.h>
#include <linux/types.h>
#include <linux/seq_file.h>
#include <linux/list.h>
#include <linux/proc_fs.h>
#include <linux/slab.h>
#include <linux/io.h>
#include <linux/platform_device.h>
#include <generated/autoconf.h>
#include <linux/kobject.h>
#include <linux/regulator/consumer.h>
#include <linux/pinctrl/consumer.h>
/*debug macros */
#define TPD_DEBUG
#define TPD_DEBUG_CODE
/* #define TPD_DEBUG_TRACK */
#define TPD_DMESG(a, arg...) \
pr_info(TPD_DEVICE ":[%s:%d] " a, __func__, __LINE__, ##arg)
#if defined(TPD_DEBUG)
#undef TPD_DEBUG
#define TPD_DEBUG(a, arg...) \
pr_info(TPD_DEVICE ":[%s:%d] " a, __func__, __LINE__, ##arg)
#else
#define TPD_DEBUG(arg...)
#endif
#define SPLIT ", "
/* register, address, configurations */
#define TPD_DEVICE "mtk-tpd"
#define TPD_X 0
#define TPD_Y 1
#define TPD_Z1 2
#define TPD_Z2 3
#define TP_DELAY (2*HZ/100)
#define TP_DRV_MAX_COUNT (20)
#define TPD_WARP_CNT (4)
#define TPD_VIRTUAL_KEY_MAX (10)
/* various mode */
#define TPD_MODE_NORMAL 0
#define TPD_MODE_KEYPAD 1
#define TPD_MODE_SW 2
#define TPD_MODE_FAV_SW 3
#define TPD_MODE_FAV_HW 4
#define TPD_MODE_RAW_DATA 5
#undef TPD_RES_X
#undef TPD_RES_Y
extern unsigned long TPD_RES_X;
extern unsigned long TPD_RES_Y;
extern int tpd_load_status; /* 0: failed, 1: success */
extern int tpd_mode;
extern int tpd_mode_axis;
extern int tpd_mode_min;
extern int tpd_mode_max;
extern int tpd_mode_keypad_tolerance;
extern int tpd_em_debounce_time;
extern int tpd_em_debounce_time0;
extern int tpd_em_debounce_time1;
extern int tpd_em_asamp;
extern int tpd_em_auto_time_interval;
extern int tpd_em_sample_cnt;
extern int tpd_calmat[];
extern int tpd_def_calmat[];
extern int tpd_calmat[];
extern int tpd_def_calmat[];
extern int TPD_DO_WARP;
extern int tpd_wb_start[];
extern int tpd_wb_end[];
extern int tpd_v_magnify_x;
extern int tpd_v_magnify_y;
extern unsigned int DISP_GetScreenHeight(void);
extern unsigned int DISP_GetScreenWidth(void);
#if defined(CONFIG_MTK_S3320) || defined(CONFIG_MTK_S3320_47) || \
defined(CONFIG_MTK_S3320_50)
extern void synaptics_init_sysfs(void);
#endif /* CONFIG_MTK_S3320 */
extern void tpd_button_init(void);
struct tpd_device {
struct device *tpd_dev;
struct regulator *reg;
struct regulator *io_reg;
struct input_dev *dev;
struct input_dev *kpd;
struct timer_list timer;
struct tasklet_struct tasklet;
int btn_state;
};
struct tpd_key_dim_local {
int key_x;
int key_y;
int key_width;
int key_height;
};
struct tpd_filter_t {
int enable; /*0: disable, 1: enable*/
int pixel_density; /*XXX pixel/cm*/
int W_W[3][4];/*filter custom setting prameters*/
unsigned int VECLOCITY_THRESHOLD[3];/*filter speed custom settings*/
};
struct tpd_dts_info {
int tpd_resolution[2];
int touch_max_num;
int use_tpd_button;
int tpd_key_num;
int tpd_key_local[4];
bool tpd_use_ext_gpio;
int rst_ext_gpio_num;
struct tpd_key_dim_local tpd_key_dim_local[4];
struct tpd_filter_t touch_filter;
};
extern struct tpd_dts_info tpd_dts_data;
struct tpd_attrs {
struct device_attribute **attr;
int num;
};
struct tpd_driver_t {
char *tpd_device_name;
int (*tpd_local_init)(void);
void (*suspend)(struct device *h);
void (*resume)(struct device *h);
int tpd_have_button;
struct tpd_attrs attrs;
};
/* #ifdef TPD_HAVE_BUTTON */
void tpd_button(unsigned int x, unsigned int y, unsigned int down);
void tpd_button_init(void);
ssize_t tpd_virtual_key(char *buf);
/* #ifndef TPD_BUTTON_HEIGHT */
/* #define TPD_BUTTON_HEIGHT TPD_RES_Y */
/* #endif */
extern int tpd_driver_add(struct tpd_driver_t *tpd_drv);
extern int tpd_driver_remove(struct tpd_driver_t *tpd_drv);
void tpd_button_setting(int keycnt, void *keys, void *keys_dim);
extern int tpd_em_spl_num;
extern int tpd_em_pressure_threshold;
extern struct tpd_device *tpd;
extern void tpd_get_dts_info(void);
#define GTP_RST_PORT 0
#define GTP_INT_PORT 1
extern void tpd_gpio_as_int(int pin);
extern void tpd_gpio_output(int pin, int level);
extern const struct of_device_id touch_of_match[];
#ifdef TPD_DEBUG_CODE
#include "tpd_debug.h"
#endif
#ifdef TPD_DEBUG_TRACK
int DAL_Clean(void);
int DAL_Printf(const char *fmt, ...);
int LCD_LayerEnable(int id, BOOL enable);
#endif
#ifdef TPD_HAVE_CALIBRATION
#include "tpd_calibrate.h"
#endif
#include "tpd_default.h"
/* switch touch panel into different mode */
void _tpd_switch_single_mode(void);
void _tpd_switch_multiple_mode(void);
void _tpd_switch_sleep_mode(void);
void _tpd_switch_normal_mode(void);
#endif
@@ -0,0 +1,123 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#include "tpd.h"
/* #ifdef TPD_HAVE_BUTTON */
/* static int tpd_keys[TPD_KEY_COUNT] = TPD_KEYS; */
/* static int tpd_keys_dim[TPD_KEY_COUNT][4] = TPD_KEYS_DIM; */
static unsigned int tpd_keycnt;
static int tpd_keys[TPD_VIRTUAL_KEY_MAX] = { 0 };
static int tpd_keys_dim[TPD_VIRTUAL_KEY_MAX][4]; /* = {0}; */
static ssize_t mtk_virtual_keys_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
int i, j;
for (i = 0, j = 0; i < tpd_keycnt; i++)
j += snprintf(buf+j, PAGE_SIZE-j, "%s%s:%d:%d:%d:%d:%d%s", buf,
__stringify(EV_KEY), tpd_keys[i],
tpd_keys_dim[i][0], tpd_keys_dim[i][1],
tpd_keys_dim[i][2], tpd_keys_dim[i][3],
(i == tpd_keycnt - 1 ? "\n" : ":"));
return j;
}
static struct kobj_attribute mtk_virtual_keys_attr = {
.attr = {
.name = "virtualkeys.mtk-tpd",
.mode = 0644,
},
.show = &mtk_virtual_keys_show,
};
static struct attribute *mtk_properties_attrs[] = {
&mtk_virtual_keys_attr.attr,
NULL
};
static struct attribute_group mtk_properties_attr_group = {
.attrs = mtk_properties_attrs,
};
struct kobject *properties_kobj;
void tpd_button_init(void)
{
int ret = 0, i = 0;
/* if((tpd->kpd=input_allocate_device())==NULL) return -ENOMEM; */
tpd->kpd = input_allocate_device();
/* struct input_dev kpd initialization and registration */
tpd->kpd->name = TPD_DEVICE "-kpd";
set_bit(EV_KEY, tpd->kpd->evbit);
/* set_bit(EV_REL, tpd->kpd->evbit); */
/* set_bit(EV_ABS, tpd->kpd->evbit); */
for (i = 0; i < tpd_keycnt; i++)
__set_bit(tpd_keys[i], tpd->kpd->keybit);
tpd->kpd->id.bustype = BUS_HOST;
tpd->kpd->id.vendor = 0x0001;
tpd->kpd->id.product = 0x0001;
tpd->kpd->id.version = 0x0100;
if (input_register_device(tpd->kpd))
TPD_DMESG("input_register_device failed.(kpd)\n");
set_bit(EV_KEY, tpd->dev->evbit);
for (i = 0; i < tpd_keycnt; i++)
__set_bit(tpd_keys[i], tpd->dev->keybit);
properties_kobj = kobject_create_and_add("board_properties", NULL);
if (properties_kobj)
ret = sysfs_create_group(properties_kobj,
&mtk_properties_attr_group);
if (!properties_kobj || ret)
TPD_DEBUG("failed to create board_properties\n");
}
void tpd_button(unsigned int x, unsigned int y, unsigned int down)
{
int i;
bool report;
if (down) {
for (i = 0; i < tpd_keycnt; i++) {
report = x >= tpd_keys_dim[i][0] -
(tpd_keys_dim[i][2] / 2) &&
x <= tpd_keys_dim[i][0] +
(tpd_keys_dim[i][2] / 2) &&
y >= tpd_keys_dim[i][1] -
(tpd_keys_dim[i][3] / 2) &&
y <= tpd_keys_dim[i][1] +
(tpd_keys_dim[i][3] / 2) &&
!(tpd->btn_state & (1 << i));
if (report) {
input_report_key(tpd->kpd, tpd_keys[i], 1);
input_sync(tpd->kpd);
tpd->btn_state |= (1 << i);
TPD_DEBUG("press key %d (%d)\n",
i, tpd_keys[i]);
}
}
} else {
for (i = 0; i < tpd_keycnt; i++) {
if (tpd->btn_state & (1 << i)) {
input_report_key(tpd->kpd, tpd_keys[i], 0);
input_sync(tpd->kpd);
TPD_DEBUG("release key %d (%d)\n",
i, tpd_keys[i]);
}
}
tpd->btn_state = 0;
}
}
void tpd_button_setting(int keycnt, void *keys, void *keys_dim)
{
tpd_keycnt = keycnt;
memcpy(tpd_keys, keys, keycnt * 4);
memcpy(tpd_keys_dim, keys_dim, keycnt * 4 * 4);
}
/* #endif */
@@ -0,0 +1,750 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#include "tpd.h"
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/miscdevice.h>
#include <linux/device.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/fb.h>
#ifdef CONFIG_MTK_MT6306_GPIO_SUPPORT
#include <mtk_6306_gpio.h>
#endif
#ifdef CONFIG_COMPAT
#include <linux/compat.h>
#endif
#if defined(CONFIG_MTK_S3320) || defined(CONFIG_MTK_S3320_50) \
|| defined(CONFIG_MTK_S3320_47) || defined(CONFIG_MTK_MIT200) \
|| defined(CONFIG_TOUCHSCREEN_SYNAPTICS_S3528) \
|| defined(CONFIG_MTK_S7020) \
|| defined(CONFIG_TOUCHSCREEN_MTK_SYNAPTICS_3320_50)
#include <linux/input/mt.h>
#endif /* CONFIG_MTK_S3320 */
/* for magnify velocity******************************************** */
#define TOUCH_IOC_MAGIC 'A'
#define TPD_GET_VELOCITY_CUSTOM_X _IO(TOUCH_IOC_MAGIC, 0)
#define TPD_GET_VELOCITY_CUSTOM_Y _IO(TOUCH_IOC_MAGIC, 1)
#define TPD_GET_FILTER_PARA _IOWR(TOUCH_IOC_MAGIC, 2, struct tpd_filter_t)
#ifdef CONFIG_COMPAT
#define COMPAT_TPD_GET_FILTER_PARA _IOWR(TOUCH_IOC_MAGIC, \
2, struct tpd_filter_t)
#endif
struct tpd_filter_t tpd_filter;
struct tpd_dts_info tpd_dts_data;
struct pinctrl *pinctrl1;
struct pinctrl_state *pins_default;
struct pinctrl_state *eint_as_int, *eint_output0,
*eint_output1, *rst_output0, *rst_output1;
const struct of_device_id touch_of_match[] = {
{ .compatible = "goodix,touch", },
{},
};
void tpd_get_dts_info(void)
{
struct device_node *node1 = NULL;
int key_dim_local[16], i;
node1 = of_find_matching_node(node1, touch_of_match);
if (node1) {
of_property_read_u32(node1,
"tpd-max-touch-num", &tpd_dts_data.touch_max_num);
of_property_read_u32(node1,
"use-tpd-button", &tpd_dts_data.use_tpd_button);
pr_debug("[tpd]use-tpd-button = %d\n",
tpd_dts_data.use_tpd_button);
if (of_property_read_u32_array(node1, "tpd-resolution",
tpd_dts_data.tpd_resolution,
ARRAY_SIZE(tpd_dts_data.tpd_resolution))) {
pr_debug("[tpd] resulution is %d %d",
tpd_dts_data.tpd_resolution[0],
tpd_dts_data.tpd_resolution[1]);
}
if (tpd_dts_data.use_tpd_button) {
of_property_read_u32(node1,
"tpd-key-num", &tpd_dts_data.tpd_key_num);
if (of_property_read_u32_array(node1, "tpd-key-local",
tpd_dts_data.tpd_key_local,
ARRAY_SIZE(tpd_dts_data.tpd_key_local)))
pr_debug("tpd-key-local: %d %d %d %d",
tpd_dts_data.tpd_key_local[0],
tpd_dts_data.tpd_key_local[1],
tpd_dts_data.tpd_key_local[2],
tpd_dts_data.tpd_key_local[3]);
if (of_property_read_u32_array(node1,
"tpd-key-dim-local",
key_dim_local, ARRAY_SIZE(key_dim_local))) {
memcpy(tpd_dts_data.tpd_key_dim_local,
key_dim_local, sizeof(key_dim_local));
for (i = 0; i < 4; i++) {
pr_debug("[tpd]key[%d].key_x = %d\n", i,
tpd_dts_data
.tpd_key_dim_local[i]
.key_x);
pr_debug("[tpd]key[%d].key_y = %d\n", i,
tpd_dts_data
.tpd_key_dim_local[i]
.key_y);
pr_debug("[tpd]key[%d].key_W = %d\n", i,
tpd_dts_data
.tpd_key_dim_local[i]
.key_width);
pr_debug("[tpd]key[%d].key_H = %d\n", i,
tpd_dts_data
.tpd_key_dim_local[i]
.key_height);
}
}
}
of_property_read_u32(node1, "tpd-filter-enable",
&tpd_dts_data.touch_filter.enable);
if (tpd_dts_data.touch_filter.enable) {
of_property_read_u32(node1,
"tpd-filter-pixel-density",
&tpd_dts_data.touch_filter.pixel_density);
if (of_property_read_u32_array(node1,
"tpd-filter-custom-prameters",
(u32 *)tpd_dts_data.touch_filter.W_W,
ARRAY_SIZE(tpd_dts_data.touch_filter.W_W)))
pr_debug("get tpd-filter-custom-parameters");
if (of_property_read_u32_array(node1,
"tpd-filter-custom-speed",
tpd_dts_data.touch_filter.VECLOCITY_THRESHOLD,
ARRAY_SIZE(tpd_dts_data
.touch_filter
.VECLOCITY_THRESHOLD)))
pr_debug("get tpd-filter-custom-speed");
}
memcpy(&tpd_filter,
&tpd_dts_data.touch_filter, sizeof(tpd_filter));
pr_debug("[tpd]tpd-filter-enable = %d, pixel_density = %d\n",
tpd_filter.enable, tpd_filter.pixel_density);
tpd_dts_data.tpd_use_ext_gpio =
of_property_read_bool(node1, "tpd-use-ext-gpio");
of_property_read_u32(node1,
"tpd-rst-ext-gpio-num",
&tpd_dts_data.rst_ext_gpio_num);
} else {
TPD_DMESG("can't find touch compatible custom node\n");
}
}
static DEFINE_MUTEX(tpd_set_gpio_mutex);
void tpd_gpio_as_int(int pin)
{
mutex_lock(&tpd_set_gpio_mutex);
TPD_DEBUG("[tpd]%s\n", __func__);
if (pin == 1)
pinctrl_select_state(pinctrl1, eint_as_int);
mutex_unlock(&tpd_set_gpio_mutex);
}
void tpd_gpio_output(int pin, int level)
{
mutex_lock(&tpd_set_gpio_mutex);
TPD_DEBUG("%s pin = %d, level = %d\n", __func__, pin, level);
if (pin == 1) {
if (level)
pinctrl_select_state(pinctrl1, eint_output1);
else
pinctrl_select_state(pinctrl1, eint_output0);
} else {
if (tpd_dts_data.tpd_use_ext_gpio) {
#ifdef CONFIG_MTK_MT6306_GPIO_SUPPORT
mt6306_set_gpio_dir(
tpd_dts_data.rst_ext_gpio_num, 1);
mt6306_set_gpio_out(
tpd_dts_data.rst_ext_gpio_num, level);
#endif
} else {
if (level)
pinctrl_select_state(pinctrl1, rst_output1);
else
pinctrl_select_state(pinctrl1, rst_output0);
}
}
mutex_unlock(&tpd_set_gpio_mutex);
}
int tpd_get_gpio_info(struct platform_device *pdev)
{
int ret;
TPD_DEBUG("[tpd %d] mt_tpd_pinctrl+++++++++++++++++\n", pdev->id);
pinctrl1 = devm_pinctrl_get(&pdev->dev);
if (IS_ERR(pinctrl1)) {
ret = PTR_ERR(pinctrl1);
dev_info(&pdev->dev, "fwq Cannot find pinctrl1!\n");
return ret;
}
pins_default = pinctrl_lookup_state(pinctrl1, "default");
if (IS_ERR(pins_default)) {
ret = PTR_ERR(pins_default);
TPD_DMESG("Cannot find pinctrl default %d!\n", ret);
}
eint_as_int = pinctrl_lookup_state(pinctrl1, "state_eint_as_int");
if (IS_ERR(eint_as_int)) {
ret = PTR_ERR(eint_as_int);
TPD_DMESG("Cannot find pinctrl state_eint_as_int!\n");
return ret;
}
eint_output0 = pinctrl_lookup_state(pinctrl1, "state_eint_output0");
if (IS_ERR(eint_output0)) {
ret = PTR_ERR(eint_output0);
TPD_DMESG("Cannot find pinctrl state_eint_output0!\n");
return ret;
}
eint_output1 = pinctrl_lookup_state(pinctrl1, "state_eint_output1");
if (IS_ERR(eint_output1)) {
ret = PTR_ERR(eint_output1);
TPD_DMESG("Cannot find pinctrl state_eint_output1!\n");
return ret;
}
if (tpd_dts_data.tpd_use_ext_gpio == false) {
rst_output0 =
pinctrl_lookup_state(pinctrl1, "state_rst_output0");
if (IS_ERR(rst_output0)) {
ret = PTR_ERR(rst_output0);
TPD_DMESG("Cannot find pinctrl state_rst_output0!\n");
return ret;
}
rst_output1 =
pinctrl_lookup_state(pinctrl1, "state_rst_output1");
if (IS_ERR(rst_output1)) {
ret = PTR_ERR(rst_output1);
TPD_DMESG("Cannot find pinctrl state_rst_output1!\n");
return ret;
}
}
TPD_DEBUG("[tpd%d] mt_tpd_pinctrl----------\n", pdev->id);
return 0;
}
static int tpd_misc_open(struct inode *inode, struct file *file)
{
return nonseekable_open(inode, file);
}
static int tpd_misc_release(struct inode *inode, struct file *file)
{
return 0;
}
#ifdef CONFIG_COMPAT
static long tpd_compat_ioctl(
struct file *file, unsigned int cmd,
unsigned long arg)
{
long ret;
void __user *arg32 = compat_ptr(arg);
if (!file->f_op || !file->f_op->unlocked_ioctl)
return -ENOTTY;
switch (cmd) {
case COMPAT_TPD_GET_FILTER_PARA:
if (arg32 == NULL) {
pr_info("invalid argument.");
return -EINVAL;
}
ret = file->f_op->unlocked_ioctl(file, TPD_GET_FILTER_PARA,
(unsigned long)arg32);
if (ret) {
pr_info("TPD_GET_FILTER_PARA unlocked_ioctl failed.");
return ret;
}
break;
default:
pr_info("tpd: unknown IOCTL: 0x%08x\n", cmd);
ret = -ENOIOCTLCMD;
break;
}
return ret;
}
#endif
static long tpd_unlocked_ioctl(struct file *file,
unsigned int cmd, unsigned long arg)
{
/* char strbuf[256]; */
void __user *data;
long err = 0;
if (_IOC_DIR(cmd) & _IOC_READ)
err = !access_ok(VERIFY_WRITE,
(void __user *)arg, _IOC_SIZE(cmd));
else if (_IOC_DIR(cmd) & _IOC_WRITE)
err = !access_ok(VERIFY_READ,
(void __user *)arg, _IOC_SIZE(cmd));
if (err) {
pr_info("tpd: access error: %08X, (%2d, %2d)\n",
cmd, _IOC_DIR(cmd), _IOC_SIZE(cmd));
return -EFAULT;
}
switch (cmd) {
case TPD_GET_VELOCITY_CUSTOM_X:
data = (void __user *)arg;
if (data == NULL) {
err = -EINVAL;
break;
}
if (copy_to_user(data,
&tpd_v_magnify_x, sizeof(tpd_v_magnify_x))) {
err = -EFAULT;
break;
}
break;
case TPD_GET_VELOCITY_CUSTOM_Y:
data = (void __user *)arg;
if (data == NULL) {
err = -EINVAL;
break;
}
if (copy_to_user(data,
&tpd_v_magnify_y, sizeof(tpd_v_magnify_y))) {
err = -EFAULT;
break;
}
break;
case TPD_GET_FILTER_PARA:
data = (void __user *) arg;
if (data == NULL) {
err = -EINVAL;
TPD_DMESG("GET_FILTER_PARA: data is null\n");
break;
}
if (copy_to_user(data, &tpd_filter,
sizeof(struct tpd_filter_t))) {
TPD_DMESG("GET_FILTER_PARA: copy data error\n");
err = -EFAULT;
break;
}
break;
default:
pr_info("tpd: unknown IOCTL: 0x%08x\n", cmd);
err = -ENOIOCTLCMD;
break;
}
return err;
}
static struct work_struct touch_resume_work;
static struct workqueue_struct *touch_resume_workqueue;
static const struct file_operations tpd_fops = {
/* .owner = THIS_MODULE, */
.open = tpd_misc_open,
.release = tpd_misc_release,
.unlocked_ioctl = tpd_unlocked_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = tpd_compat_ioctl,
#endif
};
/*---------------------------------------------------------------------------*/
static struct miscdevice tpd_misc_device = {
.minor = MISC_DYNAMIC_MINOR,
.name = "touch",
.fops = &tpd_fops,
};
/* ********************************************** */
/* #endif */
/* function definitions */
static int __init tpd_device_init(void);
static void __exit tpd_device_exit(void);
static int tpd_probe(struct platform_device *pdev);
static int tpd_remove(struct platform_device *pdev);
static struct work_struct tpd_init_work;
static struct workqueue_struct *tpd_init_workqueue;
static int tpd_suspend_flag;
int tpd_register_flag;
/* global variable definitions */
struct tpd_device *tpd;
static struct tpd_driver_t tpd_driver_list[TP_DRV_MAX_COUNT]; /* = {0}; */
struct platform_device tpd_device = {
.name = TPD_DEVICE,
.id = -1,
};
const struct dev_pm_ops tpd_pm_ops = {
.suspend = NULL,
.resume = NULL,
};
static struct platform_driver tpd_driver = {
.remove = tpd_remove,
.shutdown = NULL,
.probe = tpd_probe,
.driver = {
.name = TPD_DEVICE,
.pm = &tpd_pm_ops,
.owner = THIS_MODULE,
.of_match_table = touch_of_match,
},
};
static struct tpd_driver_t *g_tpd_drv;
/* hh: use fb_notifier */
static struct notifier_block tpd_fb_notifier;
/* use fb_notifier */
static void touch_resume_workqueue_callback(struct work_struct *work)
{
TPD_DEBUG("GTP %s\n", __func__);
g_tpd_drv->resume(NULL);
tpd_suspend_flag = 0;
}
static int tpd_fb_notifier_callback(
struct notifier_block *self,
unsigned long event, void *data)
{
struct fb_event *evdata = NULL;
int blank;
int err = 0;
TPD_DEBUG("%s\n", __func__);
evdata = data;
/* If we aren't interested in this event, skip it immediately ... */
if (event != FB_EVENT_BLANK)
return 0;
blank = *(int *)evdata->data;
TPD_DMESG("fb_notify(blank=%d)\n", blank);
switch (blank) {
case FB_BLANK_UNBLANK:
TPD_DMESG("LCD ON Notify\n");
if (g_tpd_drv && tpd_suspend_flag) {
err = queue_work(touch_resume_workqueue,
&touch_resume_work);
if (!err) {
TPD_DMESG("start resume_workqueue failed\n");
return err;
}
}
break;
case FB_BLANK_POWERDOWN:
TPD_DMESG("LCD OFF Notify\n");
if (g_tpd_drv && !tpd_suspend_flag) {
err = cancel_work_sync(&touch_resume_work);
if (!err)
TPD_DMESG("cancel resume_workqueue failed\n");
g_tpd_drv->suspend(NULL);
}
tpd_suspend_flag = 1;
break;
default:
break;
}
return 0;
}
/* Add driver: if find TPD_TYPE_CAPACITIVE driver successfully, loading it */
int tpd_driver_add(struct tpd_driver_t *tpd_drv)
{
int i;
if (g_tpd_drv != NULL) {
TPD_DMESG("touch driver exist\n");
return -1;
}
/* check parameter */
if (tpd_drv == NULL)
return -1;
tpd_drv->tpd_have_button = tpd_dts_data.use_tpd_button;
/* R-touch */
if (strcmp(tpd_drv->tpd_device_name, "generic") == 0) {
tpd_driver_list[0].tpd_device_name = tpd_drv->tpd_device_name;
tpd_driver_list[0].tpd_local_init = tpd_drv->tpd_local_init;
tpd_driver_list[0].suspend = tpd_drv->suspend;
tpd_driver_list[0].resume = tpd_drv->resume;
tpd_driver_list[0].tpd_have_button = tpd_drv->tpd_have_button;
return 0;
}
for (i = 1; i < TP_DRV_MAX_COUNT; i++) {
/* add tpd driver into list */
if (tpd_driver_list[i].tpd_device_name == NULL) {
tpd_driver_list[i].tpd_device_name =
tpd_drv->tpd_device_name;
tpd_driver_list[i].tpd_local_init =
tpd_drv->tpd_local_init;
tpd_driver_list[i].suspend = tpd_drv->suspend;
tpd_driver_list[i].resume = tpd_drv->resume;
tpd_driver_list[i].tpd_have_button =
tpd_drv->tpd_have_button;
tpd_driver_list[i].attrs = tpd_drv->attrs;
break;
}
if (strcmp(tpd_driver_list[i].tpd_device_name,
tpd_drv->tpd_device_name) == 0)
return 1; /* driver exist */
}
return 0;
}
int tpd_driver_remove(struct tpd_driver_t *tpd_drv)
{
int i = 0;
/* check parameter */
if (tpd_drv == NULL)
return -1;
for (i = 0; i < TP_DRV_MAX_COUNT; i++) {
/* find it */
if (strcmp(tpd_driver_list[i].tpd_device_name,
tpd_drv->tpd_device_name) == 0) {
memset(&tpd_driver_list[i], 0,
sizeof(struct tpd_driver_t));
break;
}
}
return 0;
}
static void tpd_create_attributes(struct device *dev, struct tpd_attrs *attrs)
{
int num = attrs->num;
for (; num > 0;) {
if (device_create_file(dev, attrs->attr[--num]))
pr_info("mtk_tpd: tpd create attributes file failed\n");
}
}
/* touch panel probe */
static int tpd_probe(struct platform_device *pdev)
{
int touch_type = 1; /* 0:R-touch, 1: Cap-touch */
int i = 0;
#ifndef CONFIG_CUSTOM_LCM_X
#ifdef CONFIG_LCM_WIDTH
unsigned long tpd_res_x = 0, tpd_res_y = 0;
int ret = 0;
#endif
#endif
TPD_DMESG("enter %s, %d\n", __func__, __LINE__);
if (misc_register(&tpd_misc_device))
pr_info("mtk_tpd: tpd_misc_device register failed\n");
tpd_get_gpio_info(pdev);
tpd = kmalloc(sizeof(struct tpd_device), GFP_KERNEL);
if (tpd == NULL)
return -ENOMEM;
memset(tpd, 0, sizeof(struct tpd_device));
/* allocate input device */
tpd->dev = input_allocate_device();
if (tpd->dev == NULL) {
kfree(tpd);
return -ENOMEM;
}
/* TPD_RES_X = simple_strtoul(LCM_WIDTH, NULL, 0); */
/* TPD_RES_Y = simple_strtoul(LCM_HEIGHT, NULL, 0); */
#ifdef CONFIG_MTK_LCM_PHYSICAL_ROTATION
if (strncmp(CONFIG_MTK_LCM_PHYSICAL_ROTATION, "90", 2) == 0
|| strncmp(CONFIG_MTK_LCM_PHYSICAL_ROTATION, "270", 3) == 0) {
#ifdef CONFIG_MTK_FB
/*Fix build errors,as some projects cannot support these apis while bring up*/
TPD_RES_Y = DISP_GetScreenWidth();
TPD_RES_X = DISP_GetScreenHeight();
#endif
} else
#endif
{
#ifdef CONFIG_CUSTOM_LCM_X
#ifndef CONFIG_FPGA_EARLY_PORTING
#if defined(CONFIG_MTK_FB) && defined(CONFIG_MTK_LCM)
/*Fix build errors,as some projects cannot support these apis while bring up*/
TPD_RES_X = DISP_GetScreenWidth();
TPD_RES_Y = DISP_GetScreenHeight();
#else
/*for some projects, we do not use mtk framebuffer*/
TPD_RES_X = tpd_dts_data.tpd_resolution[0];
TPD_RES_Y = tpd_dts_data.tpd_resolution[1];
#endif
#endif
#else
#ifdef CONFIG_LCM_WIDTH
ret = kstrtoul(CONFIG_LCM_WIDTH, 0, &tpd_res_x);
if (ret < 0) {
pr_info("Touch down get lcm_x failed");
return ret;
}
TPD_RES_X = tpd_res_x;
ret = kstrtoul(CONFIG_LCM_HEIGHT, 0, &tpd_res_x);
if (ret < 0) {
pr_info("Touch down get lcm_y failed");
return ret;
}
TPD_RES_Y = tpd_res_y;
#endif
#endif
}
if (2560 == TPD_RES_X)
TPD_RES_X = 2048;
if (1600 == TPD_RES_Y)
TPD_RES_Y = 1536;
pr_debug("mtk_tpd: TPD_RES_X = %lu, TPD_RES_Y = %lu\n",
TPD_RES_X, TPD_RES_Y);
tpd_mode = TPD_MODE_NORMAL;
tpd_mode_axis = 0;
tpd_mode_min = TPD_RES_Y / 2;
tpd_mode_max = TPD_RES_Y;
tpd_mode_keypad_tolerance = TPD_RES_X * TPD_RES_X / 1600;
/* struct input_dev dev initialization and registration */
tpd->dev->name = TPD_DEVICE;
set_bit(EV_ABS, tpd->dev->evbit);
set_bit(EV_KEY, tpd->dev->evbit);
set_bit(ABS_X, tpd->dev->absbit);
set_bit(ABS_Y, tpd->dev->absbit);
set_bit(ABS_PRESSURE, tpd->dev->absbit);
#if !defined(CONFIG_MTK_S3320) && !defined(CONFIG_MTK_S3320_47)\
&& !defined(CONFIG_MTK_S3320_50) && !defined(CONFIG_MTK_MIT200) \
&& !defined(CONFIG_TOUCHSCREEN_SYNAPTICS_S3528) \
&& !defined(CONFIG_MTK_S7020) \
&& !defined(CONFIG_TOUCHSCREEN_MTK_SYNAPTICS_3320_50)
set_bit(BTN_TOUCH, tpd->dev->keybit);
#endif /* CONFIG_MTK_S3320 */
set_bit(INPUT_PROP_DIRECT, tpd->dev->propbit);
/* save dev for regulator_get() before tpd_local_init() */
tpd->tpd_dev = &pdev->dev;
for (i = 1; i < TP_DRV_MAX_COUNT; i++) {
/* add tpd driver into list */
if (tpd_driver_list[i].tpd_device_name != NULL) {
tpd_driver_list[i].tpd_local_init();
/* msleep(1); */
if (tpd_load_status == 1) {
TPD_DMESG("%s, tpd_driver_name=%s\n", __func__,
tpd_driver_list[i].tpd_device_name);
g_tpd_drv = &tpd_driver_list[i];
break;
}
}
}
if (g_tpd_drv == NULL) {
if (tpd_driver_list[0].tpd_device_name != NULL) {
g_tpd_drv = &tpd_driver_list[0];
/* touch_type:0: r-touch, 1: C-touch */
touch_type = 0;
g_tpd_drv->tpd_local_init();
TPD_DMESG("Generic touch panel driver\n");
} else {
TPD_DMESG("no touch driver is loaded!!\n");
return 0;
}
}
touch_resume_workqueue = create_singlethread_workqueue("touch_resume");
INIT_WORK(&touch_resume_work, touch_resume_workqueue_callback);
/* use fb_notifier */
tpd_fb_notifier.notifier_call = tpd_fb_notifier_callback;
if (fb_register_client(&tpd_fb_notifier))
TPD_DMESG("register fb_notifier fail!\n");
/* TPD_TYPE_CAPACITIVE handle */
if (touch_type == 1) {
set_bit(ABS_MT_TRACKING_ID, tpd->dev->absbit);
set_bit(ABS_MT_TOUCH_MAJOR, tpd->dev->absbit);
set_bit(ABS_MT_TOUCH_MINOR, tpd->dev->absbit);
set_bit(ABS_MT_POSITION_X, tpd->dev->absbit);
set_bit(ABS_MT_POSITION_Y, tpd->dev->absbit);
input_set_abs_params(tpd->dev,
ABS_MT_POSITION_X, 0, TPD_RES_X, 0, 0);
input_set_abs_params(tpd->dev,
ABS_MT_POSITION_Y, 0, TPD_RES_Y, 0, 0);
#if defined(CONFIG_MTK_S3320) || defined(CONFIG_MTK_S3320_47) \
|| defined(CONFIG_MTK_S3320_50) || defined(CONFIG_MTK_MIT200) \
|| defined(CONFIG_TOUCHSCREEN_SYNAPTICS_S3528) \
|| defined(CONFIG_MTK_S7020) \
|| defined(CONFIG_TOUCHSCREEN_MTK_SYNAPTICS_3320_50)
input_set_abs_params(tpd->dev,
ABS_MT_PRESSURE, 0, 255, 0, 0);
input_set_abs_params(tpd->dev,
ABS_MT_WIDTH_MAJOR, 0, 15, 0, 0);
input_set_abs_params(tpd->dev, ABS_MT_WIDTH_MINOR, 0, 15, 0, 0);
input_mt_init_slots(tpd->dev, 10, 0);
#else
input_set_abs_params(tpd->dev,
ABS_MT_TOUCH_MAJOR, 0, 100, 0, 0);
input_set_abs_params(tpd->dev,
ABS_MT_TOUCH_MINOR, 0, 100, 0, 0);
#endif /* CONFIG_MTK_S3320 */
TPD_DMESG("Cap touch panel driver\n");
}
input_set_abs_params(tpd->dev, ABS_X, 0, TPD_RES_X, 0, 0);
input_set_abs_params(tpd->dev, ABS_Y, 0, TPD_RES_Y, 0, 0);
input_abs_set_res(tpd->dev, ABS_X, TPD_RES_X);
input_abs_set_res(tpd->dev, ABS_Y, TPD_RES_Y);
input_set_abs_params(tpd->dev, ABS_PRESSURE, 0, 255, 0, 0);
input_set_abs_params(tpd->dev, ABS_MT_TRACKING_ID, 0, 10, 0, 0);
if (input_register_device(tpd->dev))
TPD_DMESG("input_register_device failed.(tpd)\n");
else
tpd_register_flag = 1;
if (g_tpd_drv->tpd_have_button)
tpd_button_init();
if (g_tpd_drv->attrs.num)
tpd_create_attributes(&pdev->dev, &g_tpd_drv->attrs);
return 0;
}
static int tpd_remove(struct platform_device *pdev)
{
input_unregister_device(tpd->dev);
return 0;
}
/* called when loaded into kernel */
static void tpd_init_work_callback(struct work_struct *work)
{
TPD_DEBUG("MediaTek touch panel driver init\n");
if (platform_driver_register(&tpd_driver) != 0)
TPD_DMESG("unable to register touch panel driver.\n");
}
static int __init tpd_device_init(void)
{
int res = 0;
tpd_init_workqueue = create_singlethread_workqueue("mtk-tpd");
INIT_WORK(&tpd_init_work, tpd_init_work_callback);
res = queue_work(tpd_init_workqueue, &tpd_init_work);
if (!res)
pr_info("tpd : touch device init failed res:%d\n", res);
return 0;
}
/* should never be called */
static void __exit tpd_device_exit(void)
{
TPD_DMESG("MediaTek touch panel driver exit\n");
/* input_unregister_device(tpd->dev); */
platform_driver_unregister(&tpd_driver);
}
late_initcall(tpd_device_init);
module_exit(tpd_device_exit);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("MediaTek touch panel driver");
MODULE_AUTHOR("Kirby Wu<kirby.wu@mediatek.com>");
@@ -0,0 +1,437 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#include <linux/vmalloc.h>
#include <linux/uaccess.h>
#include <linux/major.h>
#include <linux/miscdevice.h>
#include <linux/i2c.h>
#include <linux/delay.h>
#include "tpd.h"
#include "met_ftrace_touch.h"
#ifdef TPD_DEBUG_CODE
int tpd_fail_count;
int tpd_trial_count;
int tpd_debug_nr;
module_param(tpd_debug_nr, int, 0644);
module_param(tpd_fail_count, int, 0644);
module_param(tpd_trial_count, int, 0644);
int tpd_debug_time;
long tpd_last_2_int_time[2] = { 0 };
long tpd_last_down_time;
int tpd_start_profiling;
int tpd_down_status;
module_param(tpd_debug_time, int, 0644);
void tpd_debug_set_time(void)
{
struct timeval t;
if (!tpd_debug_time && !tpd_em_log)
return;
do_gettimeofday(&t);
tpd_last_2_int_time[0] = tpd_last_2_int_time[1];
tpd_last_2_int_time[1] = (t.tv_sec & 0xFFF) * 1000000 + t.tv_usec;
/* */
/* Start profiling while receive touch DOWN event */
/* Stop profiling while the first frame is upadted */
/* */
if (!tpd_down_status) {
tpd_start_profiling = 1;
tpd_last_down_time = tpd_last_2_int_time[1];
}
}
#ifdef TPD_DEBUG_TRACK
int tpd_debug_track;
int tpd_debug_track_color;
int tpd_debug_touch_up;
module_param(tpd_debug_track, int, 0644);
void tpd_draw(int x, int y)
{
UINT16 *buf = (UINT16 *) dal_fb_addr;
buf = buf + (x + y * TPD_RES_X);
tpd_debug_track_color += (tpd_debug_track_color >= 31 ? 0 : 1);
*buf = (0xffe0 + tpd_debug_track_color);
}
void tpd_down_debug_track(int x, int y)
{
if (tpd_debug_touch_up == 1) {
DAL_Clean();
tpd_debug_touch_up = 0;
}
LCD_LayerEnable(5, TRUE);
tpd_draw(x - 1, y - 1);
tpd_draw(x, y - 1);
tpd_draw(x + 1, y - 1);
tpd_draw(x - 1, y);
tpd_draw(x + 1, y);
tpd_draw(x - 1, y + 1);
tpd_draw(x, y + 1);
tpd_draw(x + 1, y + 1);
}
void tpd_up_debug_track(int x, int y)
{
if (x == 0 && y == 0) {
tpd_debug_track_color = 0;
DAL_Clean();
}
tpd_debug_touch_up = 1;
}
#endif /* TPD_DEBUG_TRACK */
#define BUFFER_SIZE 128
int tpd_em_log;
module_param(tpd_em_log, int, 0664);
void tpd_enable_em_log(int enable)
{
if (enable)
tpd_em_log = 1;
else
tpd_em_log = 0;
}
EXPORT_SYMBOL(tpd_enable_em_log);
int tpd_em_log_to_fs;
module_param(tpd_em_log_to_fs, int, 0664);
int tpd_em_log_first = 1;
struct tpd_em_log_struct {
struct list_head list;
char data[BUFFER_SIZE];
};
static LIST_HEAD(tpd_em_log_list);
int tpd_log_line_buffer = 128; /* per line 128 bytes */
int tpd_log_line_cnt = 1024 * 10;
module_param(tpd_log_line_buffer, int, 0664);
module_param(tpd_log_line_cnt, int, 0664);
struct tpd_debug_log_buf {
unsigned int head;
unsigned int tail;
spinlock_t buffer_lock;
unsigned int cnt;
unsigned char *buffer;
};
struct tpd_debug_log_buf tpd_buf;
static int tpd_debug_log_open(struct inode *inode, struct file *file)
{
if (tpd_buf.buffer == NULL)
tpd_buf.buffer =
vmalloc(tpd_log_line_cnt * tpd_log_line_buffer);
if (tpd_buf.buffer == NULL) {
pr_info("tpd_log: nomem for tpd_buf->buffer\n");
return -ENOMEM;
}
spin_lock(&tpd_buf.buffer_lock);
tpd_buf.head = tpd_buf.tail = 0;
tpd_buf.cnt = 0;
spin_unlock(&tpd_buf.buffer_lock);
file->private_data = &tpd_buf;
pr_debug("[tpd_em_log]: open log file\n");
return 0;
}
static int tpd_debug_log_release(struct inode *inode, struct file *file)
{
unsigned char *tmp_buffer = NULL;
pr_debug("[tpd_em_log]: close log file\n");
spin_lock(&tpd_buf.buffer_lock);
tmp_buffer = tpd_buf.buffer;
tpd_buf.buffer = NULL;
spin_unlock(&tpd_buf.buffer_lock);
if (tmp_buffer)
vfree(tmp_buffer);
/* free(tpd_buf); */
return 0;
}
static ssize_t tpd_debug_log_write(struct file *file, const char __user *buffer,
size_t count, loff_t *ppos)
{
return 0;
}
static ssize_t tpd_debug_log_read(struct file *file, char __user *buffer,
size_t count, loff_t *ppos)
{
struct tpd_debug_log_buf *tpd_buf =
(struct tpd_debug_log_buf *)file->private_data;
unsigned int retval = 0, unit = tpd_log_line_buffer;
unsigned char *tmp_buf = NULL;
if (tpd_buf == NULL)
return -ENOMEM;
if (tpd_buf->head == tpd_buf->tail && (file->f_flags & O_NONBLOCK))
return -EAGAIN;
while ((count - retval) >= unit) {
spin_lock_irq(&tpd_buf->buffer_lock);
if (tpd_buf->head != tpd_buf->tail) {
tmp_buf = &tpd_buf->buffer[tpd_buf->tail++ * unit];
tpd_buf->tail &= tpd_log_line_cnt - 1;
} else {
spin_unlock_irq(&tpd_buf->buffer_lock);
break;
}
spin_unlock_irq(&tpd_buf->buffer_lock);
/* pr_info("%s, tmp_buf:0x%x\n", tmp_buf, tmp_buf); */
if (copy_to_user(buffer + retval, tmp_buf, unit))
return -EFAULT;
retval += unit;
}
return retval;
}
static unsigned char *tpd_log_find_buffer(void)
{
unsigned char *buffer = NULL;
unsigned int unit = tpd_log_line_buffer;
if (tpd_buf.buffer == NULL) {
pr_info("[tpd_em_log] :tpd_buf.buffer is NULL\n");
return NULL;
}
spin_lock(&tpd_buf.buffer_lock);
buffer = &tpd_buf.buffer[tpd_buf.head++ * unit];
tpd_buf.head &= tpd_log_line_cnt - 1;
spin_unlock(&tpd_buf.buffer_lock);
if (tpd_buf.head == tpd_buf.tail) {
snprintf(buffer, unit, "[tpd_em_log] overlay !!!!!\n");
return NULL;
}
memset(buffer, 0, unit);
return buffer;
}
static const struct file_operations tpd_debug_log_fops = {
.owner = THIS_MODULE,
.read = tpd_debug_log_read,
.write = tpd_debug_log_write,
.open = tpd_debug_log_open,
.release = tpd_debug_log_release,
};
static struct miscdevice tpd_debug_log_dev = {
.minor = MISC_DYNAMIC_MINOR,
.name = "tpd_em_log",
.fops = &tpd_debug_log_fops,
};
#ifndef CREATE_TRACE_POINTS
#define CREATE_TRACE_POINTS
#endif
noinline void MET_touch(int raw_x, int raw_y,
int cal_x, int cal_y, int p, int down)
{
struct timeval t;
do_gettimeofday(&t);
if ((tpd_down_status == 0 && down == 1) ||
(tpd_down_status == 1 && down == 0)) {
trace_MET_touch("EV_KEY",
t.tv_sec, t.tv_usec, "BTN_TOUCH", down);
tpd_down_status = !tpd_down_status;
}
if (tpd_down_status) {
trace_MET_touch("EV_ABS", t.tv_sec, t.tv_usec, "X", raw_x);
trace_MET_touch("EV_ABS", t.tv_sec, t.tv_usec, "Y", raw_y);
}
}
void tpd_em_log_output(int raw_x, int raw_y,
int cal_x, int cal_y, int p, int down)
{
if (down == TPD_TYPE_INT_DOWN) {
pr_debug("[tpd_em_log] int trigger down\n");
} else if (down == TPD_TYPE_INT_UP) {
pr_debug("[tpd_em_log] int trigger up\n");
} else if (down == TPD_TYPE_TIMER) {
pr_debug("[tpd_em_log] timer trigger\n");
} else if (down == TPD_TYPE_RAW_DATA) {
if (tpd_em_log == TPD_TYPE_RAW_DATA) {
pr_debug("[tpd_em_log] rx=%d,ry=%d,rz1=%d"
SPLIT "rz2=%d,p=%d,r\n",
raw_x, raw_y, cal_x, cal_y, p);
}
} else if (down == TPD_TYPE_REJECT1) {
pr_debug("[tpd_em_log] the first or last point is rejected\n");
} else if (down == TPD_TYPE_REJECT2) {
pr_debug
("[tpd_em_log] pressure(%d) > NICE_PRESSURE(%d)"
SPLIT "debounce debt0:%d ms, debt1:%d ms, spl_num:%d\n",
raw_x, raw_y, cal_x, cal_y, p);
} else if (down == TPD_TYPE_FIST_LATENCY) {
pr_debug("[tpd_em_log] The first touch latency is %d ms\n",
raw_x / 1000);
} else if (down && tpd_down_status == 0) {
pr_debug("[tpd_em_log] rx=%d,ry=%d,cx=%d"
SPLIT "cy=%d,p=%d,d(+%ld ms)\n",
raw_x, raw_y, cal_x, cal_y, p,
(tpd_last_2_int_time[1] -
tpd_last_2_int_time[0]) / 1000);
} else if (down && tpd_down_status != 0) {
pr_debug("[tpd_em_log] rx=%d,ry=%d,cx=%d"
SPLIT "cy=%d,p=%d,m(+%ld ms)\n",
raw_x, raw_y, cal_x, cal_y, p,
(tpd_last_2_int_time[1] -
tpd_last_2_int_time[0]) / 1000);
} else {
pr_debug("[tpd_em_log] rx=%d,ry=%d,cx=%d"
SPLIT "cy=%d,p=%d,u(+%ld ms)\n",
raw_x, raw_y, cal_x, cal_y, p,
(tpd_last_2_int_time[1] -
tpd_last_2_int_time[0]) / 1000);
}
}
void tpd_em_log_store(int raw_x, int raw_y,
int cal_x, int cal_y, int p, int down)
{
/* static struct proc_dir_entry *entry = NULL; */
/* struct tpd_em_log_struct *tpd_em_log_struct_new; */
struct timeval t;
unsigned char *buffer = NULL;
/* unsigned int unit = tpd_log_line_buffer; */
/* pr_info("[tpd_em_log]: start register log file"); */
buffer = tpd_log_find_buffer();
if (buffer == NULL) {
pr_info("not buffer\n");
return;
}
do_gettimeofday(&t);
if (down == TPD_TYPE_INT_DOWN) {
snprintf(buffer, tpd_log_line_buffer,
"[%5lu.%06lu][tpd_em_log] int trigger down\n",
(t.tv_sec & 0xFFF), t.tv_usec);
} else if (down == TPD_TYPE_INT_UP) {
snprintf(buffer, tpd_log_line_buffer,
"[%5lu.%06lu][tpd_em_log] int trigger up\n",
(t.tv_sec & 0xFFF), t.tv_usec);
} else if (down == TPD_TYPE_TIMER) {
snprintf(buffer, tpd_log_line_buffer,
"[%5lu.%06lu][tpd_em_log] timer trigger\n",
(t.tv_sec & 0xFFF), t.tv_usec);
} else if (down == TPD_TYPE_RAW_DATA) {
if (tpd_em_log == TPD_TYPE_RAW_DATA) {
snprintf(buffer, tpd_log_line_buffer,
"[%5lu.%06lu][tpd_em_log]"
SPLIT "rx=%d,ry=%d,rz1=%d,rz2=%d,p=%d,r\n",
(t.tv_sec & 0xFFF), t.tv_usec,
raw_x, raw_y, cal_x, cal_y, p);
}
} else if (down == TPD_TYPE_REJECT1) {
snprintf(buffer, tpd_log_line_buffer,
"[%5lu.%06lu][tpd_em_log]"
SPLIT "the first or last point is rejected\n",
(t.tv_sec & 0xFFF), t.tv_usec);
} else if (down == TPD_TYPE_REJECT2) {
snprintf(buffer, tpd_log_line_buffer,
"[%5lu.%06lu][tpd_em_log]"
SPLIT "pressure(%d) > NICE_PRESSURE(%d), "
SPLIT "debounce debt0:%d, debt1:%d, spl_num:%d\n",
(t.tv_sec & 0xFFF), t.tv_usec,
raw_x, raw_y, cal_x, cal_y, p);
} else if (down == TPD_TYPE_FIST_LATENCY) {
snprintf(buffer, tpd_log_line_buffer,
"[%5lu.%06lu][tpd_em_log]"
SPLIT "The first touch latency is %d ms\n",
(t.tv_sec & 0xFFF), t.tv_usec, raw_x / 1000);
} else if (down && tpd_down_status == 0) {
snprintf(buffer, tpd_log_line_buffer,
"[%5lu.%06lu][tpd_em_log]"
SPLIT "rx=%d,ry=%d,cx=%d,cy=%d,p=%d,d(+%ld ms)\n",
(t.tv_sec & 0xFFF), t.tv_usec,
raw_x, raw_y, cal_x, cal_y, p,
(tpd_last_2_int_time[1] -
tpd_last_2_int_time[0]) / 1000);
} else if (down && tpd_down_status != 0) {
snprintf(buffer, tpd_log_line_buffer,
"[%5lu.%06lu][tpd_em_log]"
SPLIT "rx=%d,ry=%d,cx=%d,cy=%d,p=%d,d(+%ld ms)\n",
(t.tv_sec & 0xFFF), t.tv_usec,
raw_x, raw_y, cal_x, cal_y, p,
(tpd_last_2_int_time[1] -
tpd_last_2_int_time[0]) / 1000);
} else {
snprintf(buffer, tpd_log_line_buffer,
"[%5lu.%06lu][tpd_em_log]"
SPLIT "rx=%d,ry=%d,cx=%d,cy=%d,p=%d,u(+%ld ms)\n",
(t.tv_sec & 0xFFF), t.tv_usec,
raw_x, raw_y, cal_x, cal_y, p,
(tpd_last_2_int_time[1] -
tpd_last_2_int_time[0]) / 1000);
}
/* list_add_tail(&tpd_em_log_struct_new->list, &tpd_em_log_list); */
}
void tpd_em_log_release(void)
{
struct tpd_em_log_struct *p, *p_tmp;
if (!tpd_em_log_first) {
remove_proc_entry("tpd_em_log", NULL);
list_for_each_entry_safe(p, p_tmp, &tpd_em_log_list, list) {
list_del(&p->list);
kfree(p);
}
tpd_em_log_first = 1;
tpd_em_log_to_fs = 0;
}
}
static int __init tpd_log_init(void)
{
if (misc_register(&tpd_debug_log_dev) < 0) {
pr_info("[tpd_em_log] :register device failed\n");
return -1;
}
pr_info("[tpd_em_log] :register device successfully\n");
spin_lock_init(&tpd_buf.buffer_lock);
return 0;
}
int tpd_debuglog;
module_param(tpd_debuglog, int, 0664);
module_init(tpd_log_init);
#endif /* TPD_DEBUG_CODE */
@@ -0,0 +1,144 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#ifndef TPD_DEBUG_H
#define TPD_DEBUG_H
#ifdef TPD_DEBUG_CODE
#include<linux/i2c.h>
extern int tpd_debug_nr;
void tpd_debug_set_time(void);
extern int tpd_debug_time;
extern long tpd_last_2_int_time[2];
extern long tpd_last_down_time;
extern int tpd_start_profiling;
extern int tpd_down_status;
#define TPD_DEBUG_PRINT_INT \
do { \
if (tpd_debug_time) { \
pr_info("tp_int\n"); \
} \
} while (0)
#define TPD_DEBUG_PRINT_UP \
do { \
if (pending == 0 && tpd_debug_time) { \
tpd_down_status = 0; \
pr_debug("up on %ld ms (+%ld ms)\n", \
(tpd_last_2_int_time[1] - tpd_last_down_time) / 1000, \
(tpd_last_2_int_time[1] - tpd_last_2_int_time[0]) / 1000); \
} \
} while (0)
#define TPD_DEBUG_PRINT_DOWN \
do { \
if (tpd_debug_time) { \
if (tpd_down_status == 0)\
pr_debug("down on 0 ms\n"); \
else \
pr_debug("move on %ld ms (+%ld ms)\n", \
(tpd_last_2_int_time[1] - \
tpd_last_down_time) / 1000, \
(tpd_last_2_int_time[1] -\
tpd_last_2_int_time[0]) / 1000); \
tpd_down_status = 1; \
} \
} while (0)
#define TPD_DEBUG_SET_TIME do { tpd_debug_set_time(); } while (0)
extern int tpd_em_log;
extern int tpd_em_log_to_fs;
extern int tpd_type_cap;
void tpd_em_log_output(int raw_x,
int raw_y, int cal_x, int cal_y, int p, int down);
void tpd_em_log_store(int raw_x,
int raw_y, int cal_x, int cal_y, int p, int down);
void tpd_em_log_release(void);
void tpd_enable_em_log(int enable);
#ifndef CREATE_TRACE_POINTS
#define CREATE_TRACE_POINTS
#endif
noinline void MET_touch(int raw_x, int raw_y,
int cal_x, int cal_y, int p, int down);
#define TPD_TYPE_RAW_DATA 2
#define TPD_TYPE_INT_DOWN 3
#define TPD_TYPE_INT_UP 4
#define TPD_TYPE_TIMER 5
#define TPD_TYPE_REJECT1 6
#define TPD_TYPE_REJECT2 7
#define TPD_TYPE_FIST_LATENCY 8
#define TPD_EM_PRINT(raw_x, raw_y, cal_x, cal_y, p, down)\
do { \
if (tpd_em_log) {\
if (!tpd_em_log_to_fs) { \
tpd_em_log_output(raw_x, \
raw_y, cal_x, cal_y, p, down); \
} else { \
tpd_em_log_store(raw_x, \
raw_y, cal_x, cal_y, p, down); \
tpd_em_log_output(raw_x, \
raw_y, cal_x, cal_y, p, down); \
} \
} else { \
if (tpd_em_log_to_fs) { \
tpd_em_log_release(); \
} \
} \
MET_touch(raw_x, raw_y, cal_x, cal_y, p, down); \
} while (0)
#ifdef TPD_DEBUG_TRACK
extern void *dal_fb_addr;
extern int tpd_debug_track;
void tpd_up_debug_track(int x, int y);
void tpd_down_debug_track(int x, int y);
#define TPD_UP_DEBUG_TRACK(x, y) \
do { \
if (tpd_debug_track) \
tpd_up_debug_track(x, y); \
} while (0)
#define TPD_DOWN_DEBUG_TRACK(x, y) \
do { \
if (tpd_debug_track) \
tpd_down_debug_track(x, y); \
} while (0)
#endif /* TPD_DEBUG_TRACK */
#endif /* TPD_DEBUG_CODE */
/* Macros that will be embedded in code */
#ifndef TPD_DEBUG_SET_TIME
#define TPD_DEBUG_SET_TIME
#endif
#ifndef TPD_DEBUG_PRINT_UP
#define TPD_DEBUG_PRINT_UP
#endif
#ifndef TPD_DEBUG_PRINT_DOWN
#define TPD_DEBUG_PRINT_DOWN
#endif
#ifndef TPD_UP_DEBUG_TRACK
#define TPD_UP_DEBUG_TRACK(x, y)
#endif
#ifndef TPD_DOWN_DEBUG_TRACK
#define TPD_DOWN_DEBUG_TRACK(x, y)
#endif
#endif /* TPD_DEBUG_H */
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#include "tpd.h"
/* #ifndef TPD_CUSTOM_TREMBLE_TOLERANCE */
int tpd_trembling_tolerance(int t, int p)
{
if (t > 5 || p > 120)
return 200;
if (p > 90)
return 64;
if (p > 80)
return 36;
return 26;
}
/* #endif */
@@ -0,0 +1,10 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#ifndef TPD_FAT_TOUCH
#define TPD_FAT_TOUCH 120
#endif
int tpd_trembling_tolerance(int t, int p);
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#include "tpd.h"
int tpd_calibrate_en;
module_param(tpd_calibrate_en, int, 0664);
int tpd_show_version;
module_param(tpd_show_version, int, 0664);
/* switch touch panel into single scan mode for decreasing interference */
void tpd_switch_single_mode(void)
{
#ifdef HAVE_SINGLE_MULTIPLE_SCAN_MODE
_tpd_switch_single_mode();
#endif
}
EXPORT_SYMBOL(tpd_switch_single_mode);
/* switch touch panel into multiple scan mode for better performance */
void tpd_switch_multiple_mode(void)
{
#ifdef HAVE_SINGLE_MULTIPLE_SCAN_MODE
_tpd_switch_multiple_mode();
#endif
}
EXPORT_SYMBOL(tpd_switch_multiple_mode);
/* switch touch panel into deep sleep mode */
void tpd_switch_sleep_mode(void)
{
#ifdef HAVE_SLEEP_NORMAL_MODE
_tpd_switch_sleep_mode();
#endif
}
EXPORT_SYMBOL(tpd_switch_sleep_mode);
/* switch touch panel back to normal mode */
void tpd_switch_normal_mode(void)
{
#ifdef HAVE_SLEEP_NORMAL_MODE
_tpd_switch_normal_mode();
#endif
}
EXPORT_SYMBOL(tpd_switch_normal_mode);
@@ -0,0 +1,69 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2019 MediaTek Inc.
*/
#include "tpd.h"
unsigned long TPD_RES_X = 480;
unsigned long TPD_RES_Y = 800;
/* #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION)) */
int tpd_calmat[8] = { 0 };
int tpd_def_calmat[8] = { 0 };
int tpd_calmat_size = 8;
int tpd_def_calmat_size = 8;
module_param_array(tpd_calmat, int, &tpd_calmat_size, 0664);
module_param_array(tpd_def_calmat, int, &tpd_def_calmat_size, 0444);
/* #endif */
/* #ifdef TPD_TYPE_CAPACITIVE */
int tpd_type_cap;
int tpd_v_magnify_x = 10;
int tpd_v_magnify_y = 10;
module_param(tpd_v_magnify_x, int, 0664);
module_param(tpd_v_magnify_y, int, 0664);
module_param(tpd_type_cap, int, 0444);
int tpd_firmware_version[2] = { 0, 0 };
int tpd_firmware_version_size = 2;
module_param_array(tpd_firmware_version, int, &tpd_firmware_version_size, 0444);
int tpd_mode = TPD_MODE_NORMAL;
int tpd_mode_axis;
int tpd_mode_min = 400; /* TPD_RES_Y/2; */
int tpd_mode_max = 800; /* TPD_RES_Y; */
/* TPD_RES_X*TPD_RES_X/1600; */
int tpd_mode_keypad_tolerance = 480 * 480 / 1600;
module_param(tpd_mode, int, 0664);
module_param(tpd_mode_axis, int, 0664);
module_param(tpd_mode_min, int, 0664);
module_param(tpd_mode_max, int, 0664);
module_param(tpd_mode_keypad_tolerance, int, 0664);
int tpd_em_debounce_time0 = 1;
int tpd_em_debounce_time; /* =0 */
int tpd_em_debounce_time1 = 4;
module_param(tpd_em_debounce_time0, int, 0664);
module_param(tpd_em_debounce_time1, int, 0664);
module_param(tpd_em_debounce_time, int, 0664);
int tpd_em_spl_num = 1;
module_param(tpd_em_spl_num, int, 0664);
int tpd_em_pressure_threshold;
module_param(tpd_em_pressure_threshold, int, 0664);
int tpd_em_auto_time_interval = 10;
module_param(tpd_em_auto_time_interval, int, 0664);
int tpd_em_sample_cnt = 16;
module_param(tpd_em_sample_cnt, int, 0664);
int tpd_load_status;
module_param(tpd_load_status, int, 0664);
int tpd_em_asamp = 1;
module_param(tpd_em_asamp, int, 0664);