123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- /*
- *
- * 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 <linux/kernel.h>
- #include <linux/device.h>
- #include <linux/i2c.h>
- #include <linux/spi/spi.h>
- #include <linux/input.h>
- #include <linux/input/mt.h>
- #include <linux/interrupt.h>
- #include <linux/irq.h>
- #include <linux/delay.h>
- #include <linux/slab.h>
- #include <linux/vmalloc.h>
- #include <linux/gpio.h>
- #include <linux/regulator/consumer.h>
- #include <asm/uaccess.h>
- #include <linux/firmware.h>
- #include <linux/debugfs.h>
- #include <linux/mutex.h>
- #include <linux/workqueue.h>
- #include <linux/wait.h>
- #include <linux/time.h>
- #include <linux/jiffies.h>
- #include <linux/fs.h>
- #include <linux/proc_fs.h>
- #include <linux/version.h>
- #include <linux/types.h>
- #include <linux/sched.h>
- #include <linux/kthread.h>
- #include <linux/dma-mapping.h>
- #if defined(CONFIG_FTS_TRUSTED_TOUCH)
- #include <linux/gunyah/gh_irq_lend.h>
- #include <linux/gunyah/gh_mem_notifier.h>
- #endif
- #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_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
- /*****************************************************************************
- * Alternative mode (When something goes wrong, the modules may be able to solve the problem.)
- *****************************************************************************/
- /*
- * For commnication error in PM(deep sleep) state
- */
- #define FTS_PATCH_COMERR_PM 0
- #define FTS_TIMEOUT_COMERR_PM 700
- /*****************************************************************************
- * 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 type;
- 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;
- };
- enum trusted_touch_mode_config {
- TRUSTED_TOUCH_VM_MODE,
- TRUSTED_TOUCH_MODE_NONE
- };
- enum trusted_touch_pvm_states {
- TRUSTED_TOUCH_PVM_INIT,
- PVM_I2C_RESOURCE_ACQUIRED,
- PVM_INTERRUPT_DISABLED,
- PVM_IOMEM_LENT,
- PVM_IOMEM_LENT_NOTIFIED,
- PVM_IRQ_LENT,
- PVM_IRQ_LENT_NOTIFIED,
- PVM_IOMEM_RELEASE_NOTIFIED,
- PVM_IRQ_RELEASE_NOTIFIED,
- PVM_ALL_RESOURCES_RELEASE_NOTIFIED,
- PVM_IRQ_RECLAIMED,
- PVM_IOMEM_RECLAIMED,
- PVM_INTERRUPT_ENABLED,
- PVM_I2C_RESOURCE_RELEASED,
- TRUSTED_TOUCH_PVM_STATE_MAX
- };
- enum trusted_touch_tvm_states {
- TRUSTED_TOUCH_TVM_INIT,
- TVM_IOMEM_LENT_NOTIFIED,
- TVM_IRQ_LENT_NOTIFIED,
- TVM_ALL_RESOURCES_LENT_NOTIFIED,
- TVM_IOMEM_ACCEPTED,
- TVM_I2C_SESSION_ACQUIRED,
- TVM_IRQ_ACCEPTED,
- TVM_INTERRUPT_ENABLED,
- TVM_INTERRUPT_DISABLED,
- TVM_IRQ_RELEASED,
- TVM_I2C_SESSION_RELEASED,
- TVM_IOMEM_RELEASED,
- TRUSTED_TOUCH_TVM_STATE_MAX
- };
- #ifdef CONFIG_FTS_TRUSTED_TOUCH
- #define TRUSTED_TOUCH_MEM_LABEL 0x7
- #define TOUCH_RESET_GPIO_BASE 0xF114000
- #define TOUCH_RESET_GPIO_SIZE 0x1000
- #define TOUCH_RESET_GPIO_OFFSET 0x4
- #define TOUCH_INTR_GPIO_BASE 0xF115000
- #define TOUCH_INTR_GPIO_SIZE 0x1000
- #define TOUCH_INTR_GPIO_OFFSET 0x8
- #define TRUSTED_TOUCH_EVENT_LEND_FAILURE -1
- #define TRUSTED_TOUCH_EVENT_LEND_NOTIFICATION_FAILURE -2
- #define TRUSTED_TOUCH_EVENT_ACCEPT_FAILURE -3
- #define TRUSTED_TOUCH_EVENT_FUNCTIONAL_FAILURE -4
- #define TRUSTED_TOUCH_EVENT_RELEASE_FAILURE -5
- #define TRUSTED_TOUCH_EVENT_RECLAIM_FAILURE -6
- #define TRUSTED_TOUCH_EVENT_I2C_FAILURE -7
- #define TRUSTED_TOUCH_EVENT_NOTIFICATIONS_PENDING 5
- struct trusted_touch_vm_info {
- enum gh_irq_label irq_label;
- enum gh_mem_notifier_tag mem_tag;
- enum gh_vm_names vm_name;
- const char *trusted_touch_type;
- u32 hw_irq;
- gh_memparcel_handle_t vm_mem_handle;
- u32 *iomem_bases;
- u32 *iomem_sizes;
- u32 iomem_list_size;
- void *mem_cookie;
- atomic_t vm_state;
- };
- #endif
- 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 work_struct suspend_work;
- struct ftxxxx_proc proc;
- spinlock_t irq_lock;
- struct mutex report_mutex;
- struct mutex bus_lock;
- struct mutex transition_lock;
- int irq;
- int log_level;
- int fw_is_running; /* confirm fw is running when using spi:default 0 */
- int dummy_byte;
- #if defined(CONFIG_PM) && FTS_PATCH_COMERR_PM
- struct completion pm_completion;
- bool pm_suspend;
- #endif
- bool suspended;
- bool fw_loading;
- bool irq_disabled;
- bool power_disabled;
- bool glove_mode;
- bool cover_mode;
- bool charger_mode;
- bool gesture_mode; /* gesture enable or disable, default: disable */
- int report_rate;
- /* multi-touch */
- struct ts_event *events;
- u8 *bus_tx_buf;
- u8 *bus_rx_buf;
- int bus_type;
- u8 *point_buf;
- void *notifier_cookie;
- 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
- #ifdef CONFIG_FTS_TRUSTED_TOUCH
- struct trusted_touch_vm_info *vm_info;
- struct mutex fts_clk_io_ctrl_mutex;
- const char *touch_environment;
- struct completion trusted_touch_powerdown;
- struct clk *core_clk;
- struct clk *iface_clk;
- atomic_t trusted_touch_initialized;
- atomic_t trusted_touch_enabled;
- atomic_t trusted_touch_transition;
- atomic_t trusted_touch_event;
- atomic_t trusted_touch_abort_status;
- atomic_t trusted_touch_mode;
- #endif
- atomic_t delayed_vm_probe_pending;
- };
- enum _FTS_BUS_TYPE {
- BUS_TYPE_NONE,
- BUS_TYPE_I2C,
- BUS_TYPE_SPI,
- BUS_TYPE_SPI_V2,
- };
- /*****************************************************************************
- * 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 */
- 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);
- /* Apk and functions */
- int fts_create_apk_debug_channel(struct fts_ts_data *);
- void fts_release_apk_debug_channel(struct fts_ts_data *);
- /* ADB functions */
- int fts_create_sysfs(struct fts_ts_data *ts_data);
- int fts_remove_sysfs(struct fts_ts_data *ts_data);
- /* 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_enter_test_environment(bool test_state);
- /* 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);
- int fts_ts_handle_trusted_touch_pvm(struct fts_ts_data *ts_data, int value);
- int fts_ts_handle_trusted_touch_tvm(struct fts_ts_data *ts_data, int value);
- #ifdef CONFIG_FTS_TRUSTED_TOUCH
- #ifdef CONFIG_ARCH_QTI_VM
- void fts_ts_trusted_touch_tvm_i2c_failure_report(struct fts_ts_data *fts_data);
- #endif
- #endif
- #endif /* __LINUX_FOCALTECH_CORE_H__ */
|