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 static const char * const cyttsp4_tch_abs_string[] = {
244 [CY_TCH_MAJ] = "MAJ",
245 [CY_TCH_MIN] = "MIN",
247 [CY_TCH_NUM_ABS] = "INVALID"
250 struct cyttsp4_touch {
251 int abs[CY_TCH_NUM_ABS];
254 struct cyttsp4_tch_abs_params {
255 size_t ofs; /* abs byte offset */
256 size_t size; /* size in bits */
257 size_t max; /* max value */
258 size_t bofs; /* bit offset */
261 struct cyttsp4_sysinfo_ofs {
267 size_t num_btn_regs; /* ceil(num_btns/4) */
276 size_t x_origin; /* left or right corner */
278 size_t y_origin; /* upper or lower corner */
292 size_t btn_keys_size;
293 struct cyttsp4_tch_abs_params tch_abs[CY_TCH_NUM_ABS];
294 size_t btn_rec_size; /* btn record size (in bytes) */
295 size_t btn_diff_ofs;/* btn data loc ,diff counts, (Op-Mode byte ofs) */
296 size_t btn_diff_size;/* btn size of diff counts (in bits) */
299 enum cyttsp4_btn_state {
307 int state; /* CY_BTN_PRESSED, CY_BTN_RELEASED */
311 struct cyttsp4_sysinfo {
313 struct cyttsp4_sysinfo_data si_data;
314 struct cyttsp4_sysinfo_ptr si_ptrs;
315 struct cyttsp4_sysinfo_ofs si_ofs;
316 struct cyttsp4_btn *btn; /* button states */
317 u8 *btn_rec_data; /* button diff count data */
318 u8 *xy_mode; /* operational mode and status regs */
319 u8 *xy_data; /* operational touch regs */
322 struct cyttsp4_mt_data {
323 struct cyttsp4_mt_platform_data *pdata;
324 struct cyttsp4_sysinfo *si;
325 struct input_dev *input;
326 struct mutex report_lock;
334 struct mutex system_lock;
335 struct mutex adap_lock;
336 enum cyttsp4_mode mode;
337 enum cyttsp4_sleep_state sleep_state;
338 enum cyttsp4_startup_state startup_state;
340 wait_queue_head_t wait_q;
342 struct work_struct startup_work;
343 struct work_struct watchdog_work;
344 struct timer_list watchdog_timer;
345 struct cyttsp4_sysinfo sysinfo;
349 bool invalid_touch_app;
350 struct cyttsp4_mt_data md;
351 struct cyttsp4_platform_data *pdata;
352 struct cyttsp4_core_platform_data *cpdata;
353 const struct cyttsp4_bus_ops *bus_ops;
356 u8 pr_buf[CY_MAX_PRBUF_SIZE];
360 struct cyttsp4_bus_ops {
362 int (*write)(struct device *dev, u8 *xfer_buf, u16 addr, u8 length,
364 int (*read)(struct device *dev, u8 *xfer_buf, u16 addr, u8 length,
368 enum cyttsp4_hst_mode_bits {
369 CY_HST_TOGGLE = (1 << 7),
370 CY_HST_MODE_CHANGE = (1 << 3),
371 CY_HST_MODE = (7 << 4),
372 CY_HST_OPERATE = (0 << 4),
373 CY_HST_SYSINFO = (1 << 4),
374 CY_HST_CAT = (2 << 4),
375 CY_HST_LOWPOW = (1 << 2),
376 CY_HST_SLEEP = (1 << 1),
377 CY_HST_RESET = (1 << 0),
381 #define CY_IGNORE_VALUE 0xFFFF
383 /* abs signal capabilities offsets in the frameworks array */
384 enum cyttsp4_sig_caps {
390 CY_NUM_ABS_SET /* number of signal capability fields */
393 /* abs axis signal offsets in the framworks array */
394 enum cyttsp4_sig_ost {
403 CY_NUM_ABS_OST /* number of abs signals */
408 CY_FLAG_HOVER = 0x04,
410 CY_FLAG_INV_X = 0x10,
411 CY_FLAG_INV_Y = 0x20,
412 CY_FLAG_VKEYS = 0x40,
415 enum cyttsp4_object_id {
416 CY_OBJ_STANDARD_FINGER,
422 enum cyttsp4_event_id {
425 CY_EV_MOVE, /* significant displacement (> act dist) */
426 CY_EV_LIFTOFF, /* record reports last position */
429 /* x-axis resolution of panel in pixels */
430 #define CY_PCFG_RESOLUTION_X_MASK 0x7F
432 /* y-axis resolution of panel in pixels */
433 #define CY_PCFG_RESOLUTION_Y_MASK 0x7F
435 /* x-axis, 0:origin is on left side of panel, 1: right */
436 #define CY_PCFG_ORIGIN_X_MASK 0x80
438 /* y-axis, 0:origin is on top side of panel, 1: bottom */
439 #define CY_PCFG_ORIGIN_Y_MASK 0x80
441 static inline int cyttsp4_adap_read(struct cyttsp4 *ts, u16 addr, int size,
444 return ts->bus_ops->read(ts->dev, ts->xfer_buf, addr, size, buf);
447 static inline int cyttsp4_adap_write(struct cyttsp4 *ts, u16 addr, int size,
450 return ts->bus_ops->write(ts->dev, ts->xfer_buf, addr, size, buf);
453 extern struct cyttsp4 *cyttsp4_probe(const struct cyttsp4_bus_ops *ops,
454 struct device *dev, u16 irq, size_t xfer_buf_size);
455 extern int cyttsp4_remove(struct cyttsp4 *ts);
456 int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, u16 addr,
457 u8 length, const void *values);
458 int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf, u16 addr,
459 u8 length, void *values);
460 extern const struct dev_pm_ops cyttsp4_pm_ops;
462 #endif /* _LINUX_CYTTSP4_CORE_H */