1 /* SPDX-License-Identifier: GPL-2.0-only */
4 * Cypress TrueTouch(TM) Standard Product V4 Core driver module.
5 * For use with Cypress Txx4xx parts.
6 * Supported parts include:
10 * Copyright (C) 2012 Cypress Semiconductor
15 #ifndef _LINUX_CYTTSP4_CORE_H
16 #define _LINUX_CYTTSP4_CORE_H
18 #include <linux/device.h>
19 #include <linux/err.h>
20 #include <linux/input.h>
21 #include <linux/kernel.h>
22 #include <linux/limits.h>
23 #include <linux/module.h>
24 #include <linux/stringify.h>
25 #include <linux/types.h>
26 #include <linux/platform_data/cyttsp4.h>
28 #define CY_REG_BASE 0x00
30 #define CY_POST_CODEL_WDG_RST 0x01
31 #define CY_POST_CODEL_CFG_DATA_CRC_FAIL 0x02
32 #define CY_POST_CODEL_PANEL_TEST_FAIL 0x04
34 #define CY_NUM_BTN_PER_REG 4
36 /* touch record system information offset masks and shifts */
37 #define CY_BYTE_OFS_MASK 0x1F
38 #define CY_BOFS_MASK 0xE0
39 #define CY_BOFS_SHIFT 5
41 #define CY_TMA1036_TCH_REC_SIZE 6
42 #define CY_TMA4XX_TCH_REC_SIZE 9
43 #define CY_TMA1036_MAX_TCH 0x0E
44 #define CY_TMA4XX_MAX_TCH 0x1E
46 #define CY_NORMAL_ORIGIN 0 /* upper, left corner */
47 #define CY_INVERT_ORIGIN 1 /* lower, right corner */
50 #define GET_NUM_TOUCHES(x) ((x) & 0x1F)
51 #define IS_LARGE_AREA(x) ((x) & 0x20)
52 #define IS_BAD_PKT(x) ((x) & 0x20)
53 #define IS_BOOTLOADER(hst_mode, reset_detect) \
54 ((hst_mode) & 0x01 || (reset_detect) != 0)
55 #define IS_TMO(t) ((t) == 0)
58 enum cyttsp_cmd_bits {
59 CY_CMD_COMPLETE = (1 << 6),
63 #define CY_WATCHDOG_TIMEOUT 1000
65 #define CY_MAX_PRINT_SIZE 512
67 #define CY_MAX_PRBUF_SIZE PIPE_BUF
68 #define CY_PR_TRUNCATED " truncated..."
71 enum cyttsp4_ic_grpnum {
72 CY_IC_GRPNUM_RESERVED,
73 CY_IC_GRPNUM_CMD_REGS,
75 CY_IC_GRPNUM_DATA_REC,
76 CY_IC_GRPNUM_TEST_REC,
77 CY_IC_GRPNUM_PCFG_REC,
78 CY_IC_GRPNUM_TCH_PARM_VAL,
79 CY_IC_GRPNUM_TCH_PARM_SIZE,
80 CY_IC_GRPNUM_RESERVED1,
81 CY_IC_GRPNUM_RESERVED2,
82 CY_IC_GRPNUM_OPCFG_REC,
83 CY_IC_GRPNUM_DDATA_REC,
84 CY_IC_GRPNUM_MDATA_REC,
85 CY_IC_GRPNUM_TEST_REGS,
86 CY_IC_GRPNUM_BTN_KEYS,
87 CY_IC_GRPNUM_TTHE_REGS,
91 enum cyttsp4_int_state {
93 CY_INT_IGNORE = (1 << 0),
94 CY_INT_MODE_CHANGE = (1 << 1),
95 CY_INT_EXEC_CMD = (1 << 2),
96 CY_INT_AWAKE = (1 << 3),
101 CY_MODE_BOOTLOADER = (1 << 1),
102 CY_MODE_OPERATIONAL = (1 << 2),
103 CY_MODE_SYSINFO = (1 << 3),
104 CY_MODE_CAT = (1 << 4),
105 CY_MODE_STARTUP = (1 << 5),
106 CY_MODE_LOADER = (1 << 6),
107 CY_MODE_CHANGE_MODE = (1 << 7),
108 CY_MODE_CHANGED = (1 << 8),
109 CY_MODE_CMD_COMPLETE = (1 << 9),
112 enum cyttsp4_sleep_state {
119 enum cyttsp4_startup_state {
125 #define CY_NUM_REVCTRL 8
126 struct cyttsp4_cydata {
131 u8 revctrl[CY_NUM_REVCTRL];
149 struct cyttsp4_test {
154 struct cyttsp4_pcfg {
170 struct cyttsp4_tch_rec_params {
175 #define CY_NUM_TCH_FIELDS 7
176 #define CY_NUM_EXT_TCH_FIELDS 3
177 struct cyttsp4_opcfg {
187 struct cyttsp4_tch_rec_params tch_rec_old[CY_NUM_TCH_FIELDS];
188 u8 btn_rec_size; /* btn record size (in bytes) */
189 u8 btn_diff_ofs; /* btn data loc, diff counts */
190 u8 btn_diff_size; /* btn size of diff counts (in bits) */
191 struct cyttsp4_tch_rec_params tch_rec_new[CY_NUM_EXT_TCH_FIELDS];
194 struct cyttsp4_sysinfo_ptr {
195 struct cyttsp4_cydata *cydata;
196 struct cyttsp4_test *test;
197 struct cyttsp4_pcfg *pcfg;
198 struct cyttsp4_opcfg *opcfg;
199 struct cyttsp4_ddata *ddata;
200 struct cyttsp4_mdata *mdata;
203 struct cyttsp4_sysinfo_data {
222 enum cyttsp4_tch_abs { /* for ordering within the extracted touch data array */
225 CY_TCH_P, /* P (Z) */
226 CY_TCH_T, /* TOUCH ID */
227 CY_TCH_E, /* EVENT ID */
228 CY_TCH_O, /* OBJECT ID */
230 CY_TCH_MAJ, /* TOUCH_MAJOR */
231 CY_TCH_MIN, /* TOUCH_MINOR */
232 CY_TCH_OR, /* ORIENTATION */
236 struct cyttsp4_touch {
237 int abs[CY_TCH_NUM_ABS];
240 struct cyttsp4_tch_abs_params {
241 size_t ofs; /* abs byte offset */
242 size_t size; /* size in bits */
243 size_t max; /* max value */
244 size_t bofs; /* bit offset */
247 struct cyttsp4_sysinfo_ofs {
253 size_t num_btn_regs; /* ceil(num_btns/4) */
262 size_t x_origin; /* left or right corner */
264 size_t y_origin; /* upper or lower corner */
278 size_t btn_keys_size;
279 struct cyttsp4_tch_abs_params tch_abs[CY_TCH_NUM_ABS];
280 size_t btn_rec_size; /* btn record size (in bytes) */
281 size_t btn_diff_ofs;/* btn data loc ,diff counts, (Op-Mode byte ofs) */
282 size_t btn_diff_size;/* btn size of diff counts (in bits) */
285 enum cyttsp4_btn_state {
293 int state; /* CY_BTN_PRESSED, CY_BTN_RELEASED */
297 struct cyttsp4_sysinfo {
299 struct cyttsp4_sysinfo_data si_data;
300 struct cyttsp4_sysinfo_ptr si_ptrs;
301 struct cyttsp4_sysinfo_ofs si_ofs;
302 struct cyttsp4_btn *btn; /* button states */
303 u8 *btn_rec_data; /* button diff count data */
304 u8 *xy_mode; /* operational mode and status regs */
305 u8 *xy_data; /* operational touch regs */
308 struct cyttsp4_mt_data {
309 struct cyttsp4_mt_platform_data *pdata;
310 struct cyttsp4_sysinfo *si;
311 struct input_dev *input;
312 struct mutex report_lock;
320 struct mutex system_lock;
321 struct mutex adap_lock;
322 enum cyttsp4_mode mode;
323 enum cyttsp4_sleep_state sleep_state;
324 enum cyttsp4_startup_state startup_state;
326 wait_queue_head_t wait_q;
328 struct work_struct startup_work;
329 struct work_struct watchdog_work;
330 struct timer_list watchdog_timer;
331 struct cyttsp4_sysinfo sysinfo;
335 bool invalid_touch_app;
336 struct cyttsp4_mt_data md;
337 struct cyttsp4_platform_data *pdata;
338 struct cyttsp4_core_platform_data *cpdata;
339 const struct cyttsp4_bus_ops *bus_ops;
342 u8 pr_buf[CY_MAX_PRBUF_SIZE];
346 struct cyttsp4_bus_ops {
348 int (*write)(struct device *dev, u8 *xfer_buf, u16 addr, u8 length,
350 int (*read)(struct device *dev, u8 *xfer_buf, u16 addr, u8 length,
354 enum cyttsp4_hst_mode_bits {
355 CY_HST_TOGGLE = (1 << 7),
356 CY_HST_MODE_CHANGE = (1 << 3),
357 CY_HST_MODE = (7 << 4),
358 CY_HST_OPERATE = (0 << 4),
359 CY_HST_SYSINFO = (1 << 4),
360 CY_HST_CAT = (2 << 4),
361 CY_HST_LOWPOW = (1 << 2),
362 CY_HST_SLEEP = (1 << 1),
363 CY_HST_RESET = (1 << 0),
367 #define CY_IGNORE_VALUE 0xFFFF
369 /* abs signal capabilities offsets in the frameworks array */
370 enum cyttsp4_sig_caps {
376 CY_NUM_ABS_SET /* number of signal capability fields */
379 /* abs axis signal offsets in the framworks array */
380 enum cyttsp4_sig_ost {
389 CY_NUM_ABS_OST /* number of abs signals */
394 CY_FLAG_HOVER = 0x04,
396 CY_FLAG_INV_X = 0x10,
397 CY_FLAG_INV_Y = 0x20,
398 CY_FLAG_VKEYS = 0x40,
401 enum cyttsp4_object_id {
402 CY_OBJ_STANDARD_FINGER,
408 enum cyttsp4_event_id {
411 CY_EV_MOVE, /* significant displacement (> act dist) */
412 CY_EV_LIFTOFF, /* record reports last position */
415 /* x-axis resolution of panel in pixels */
416 #define CY_PCFG_RESOLUTION_X_MASK 0x7F
418 /* y-axis resolution of panel in pixels */
419 #define CY_PCFG_RESOLUTION_Y_MASK 0x7F
421 /* x-axis, 0:origin is on left side of panel, 1: right */
422 #define CY_PCFG_ORIGIN_X_MASK 0x80
424 /* y-axis, 0:origin is on top side of panel, 1: bottom */
425 #define CY_PCFG_ORIGIN_Y_MASK 0x80
427 static inline int cyttsp4_adap_read(struct cyttsp4 *ts, u16 addr, int size,
430 return ts->bus_ops->read(ts->dev, ts->xfer_buf, addr, size, buf);
433 static inline int cyttsp4_adap_write(struct cyttsp4 *ts, u16 addr, int size,
436 return ts->bus_ops->write(ts->dev, ts->xfer_buf, addr, size, buf);
439 extern struct cyttsp4 *cyttsp4_probe(const struct cyttsp4_bus_ops *ops,
440 struct device *dev, u16 irq, size_t xfer_buf_size);
441 extern int cyttsp4_remove(struct cyttsp4 *ts);
442 int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, u16 addr,
443 u8 length, const void *values);
444 int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf, u16 addr,
445 u8 length, void *values);
446 extern const struct dev_pm_ops cyttsp4_pm_ops;
448 #endif /* _LINUX_CYTTSP4_CORE_H */