3 * Cypress TrueTouch(TM) Standard Product V4 Core driver module.
4 * For use with Cypress Txx4xx parts.
5 * Supported parts include:
9 * Copyright (C) 2012 Cypress Semiconductor
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * version 2, and only version 2, as published by the
14 * Free Software Foundation.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * Contact Cypress Semiconductor at www.cypress.com <ttdrivers@cypress.com>
25 #ifndef _LINUX_CYTTSP4_CORE_H
26 #define _LINUX_CYTTSP4_CORE_H
28 #include <linux/device.h>
29 #include <linux/err.h>
30 #include <linux/input.h>
31 #include <linux/kernel.h>
32 #include <linux/limits.h>
33 #include <linux/module.h>
34 #include <linux/stringify.h>
35 #include <linux/types.h>
36 #include <linux/platform_data/cyttsp4.h>
38 #define CY_REG_BASE 0x00
40 #define CY_POST_CODEL_WDG_RST 0x01
41 #define CY_POST_CODEL_CFG_DATA_CRC_FAIL 0x02
42 #define CY_POST_CODEL_PANEL_TEST_FAIL 0x04
44 #define CY_NUM_BTN_PER_REG 4
46 /* touch record system information offset masks and shifts */
47 #define CY_BYTE_OFS_MASK 0x1F
48 #define CY_BOFS_MASK 0xE0
49 #define CY_BOFS_SHIFT 5
51 #define CY_TMA1036_TCH_REC_SIZE 6
52 #define CY_TMA4XX_TCH_REC_SIZE 9
53 #define CY_TMA1036_MAX_TCH 0x0E
54 #define CY_TMA4XX_MAX_TCH 0x1E
56 #define CY_NORMAL_ORIGIN 0 /* upper, left corner */
57 #define CY_INVERT_ORIGIN 1 /* lower, right corner */
60 #define GET_NUM_TOUCHES(x) ((x) & 0x1F)
61 #define IS_LARGE_AREA(x) ((x) & 0x20)
62 #define IS_BAD_PKT(x) ((x) & 0x20)
63 #define IS_BOOTLOADER(hst_mode, reset_detect) \
64 ((hst_mode) & 0x01 || (reset_detect) != 0)
65 #define IS_TMO(t) ((t) == 0)
68 enum cyttsp_cmd_bits
{
69 CY_CMD_COMPLETE
= (1 << 6),
73 #define CY_WATCHDOG_TIMEOUT 1000
75 #define CY_MAX_PRINT_SIZE 512
77 #define CY_MAX_PRBUF_SIZE PIPE_BUF
78 #define CY_PR_TRUNCATED " truncated..."
81 enum cyttsp4_ic_grpnum
{
82 CY_IC_GRPNUM_RESERVED
,
83 CY_IC_GRPNUM_CMD_REGS
,
85 CY_IC_GRPNUM_DATA_REC
,
86 CY_IC_GRPNUM_TEST_REC
,
87 CY_IC_GRPNUM_PCFG_REC
,
88 CY_IC_GRPNUM_TCH_PARM_VAL
,
89 CY_IC_GRPNUM_TCH_PARM_SIZE
,
90 CY_IC_GRPNUM_RESERVED1
,
91 CY_IC_GRPNUM_RESERVED2
,
92 CY_IC_GRPNUM_OPCFG_REC
,
93 CY_IC_GRPNUM_DDATA_REC
,
94 CY_IC_GRPNUM_MDATA_REC
,
95 CY_IC_GRPNUM_TEST_REGS
,
96 CY_IC_GRPNUM_BTN_KEYS
,
97 CY_IC_GRPNUM_TTHE_REGS
,
101 enum cyttsp4_int_state
{
103 CY_INT_IGNORE
= (1 << 0),
104 CY_INT_MODE_CHANGE
= (1 << 1),
105 CY_INT_EXEC_CMD
= (1 << 2),
106 CY_INT_AWAKE
= (1 << 3),
111 CY_MODE_BOOTLOADER
= (1 << 1),
112 CY_MODE_OPERATIONAL
= (1 << 2),
113 CY_MODE_SYSINFO
= (1 << 3),
114 CY_MODE_CAT
= (1 << 4),
115 CY_MODE_STARTUP
= (1 << 5),
116 CY_MODE_LOADER
= (1 << 6),
117 CY_MODE_CHANGE_MODE
= (1 << 7),
118 CY_MODE_CHANGED
= (1 << 8),
119 CY_MODE_CMD_COMPLETE
= (1 << 9),
122 enum cyttsp4_sleep_state
{
129 enum cyttsp4_startup_state
{
135 #define CY_NUM_REVCTRL 8
136 struct cyttsp4_cydata
{
141 u8 revctrl
[CY_NUM_REVCTRL
];
159 struct cyttsp4_test
{
164 struct cyttsp4_pcfg
{
180 struct cyttsp4_tch_rec_params
{
185 #define CY_NUM_TCH_FIELDS 7
186 #define CY_NUM_EXT_TCH_FIELDS 3
187 struct cyttsp4_opcfg
{
197 struct cyttsp4_tch_rec_params tch_rec_old
[CY_NUM_TCH_FIELDS
];
198 u8 btn_rec_size
; /* btn record size (in bytes) */
199 u8 btn_diff_ofs
; /* btn data loc, diff counts */
200 u8 btn_diff_size
; /* btn size of diff counts (in bits) */
201 struct cyttsp4_tch_rec_params tch_rec_new
[CY_NUM_EXT_TCH_FIELDS
];
204 struct cyttsp4_sysinfo_ptr
{
205 struct cyttsp4_cydata
*cydata
;
206 struct cyttsp4_test
*test
;
207 struct cyttsp4_pcfg
*pcfg
;
208 struct cyttsp4_opcfg
*opcfg
;
209 struct cyttsp4_ddata
*ddata
;
210 struct cyttsp4_mdata
*mdata
;
213 struct cyttsp4_sysinfo_data
{
232 enum cyttsp4_tch_abs
{ /* for ordering within the extracted touch data array */
235 CY_TCH_P
, /* P (Z) */
236 CY_TCH_T
, /* TOUCH ID */
237 CY_TCH_E
, /* EVENT ID */
238 CY_TCH_O
, /* OBJECT ID */
240 CY_TCH_MAJ
, /* TOUCH_MAJOR */
241 CY_TCH_MIN
, /* TOUCH_MINOR */
242 CY_TCH_OR
, /* ORIENTATION */
246 static const char * const cyttsp4_tch_abs_string
[] = {
254 [CY_TCH_MAJ
] = "MAJ",
255 [CY_TCH_MIN
] = "MIN",
257 [CY_TCH_NUM_ABS
] = "INVALID"
260 struct cyttsp4_touch
{
261 int abs
[CY_TCH_NUM_ABS
];
264 struct cyttsp4_tch_abs_params
{
265 size_t ofs
; /* abs byte offset */
266 size_t size
; /* size in bits */
267 size_t max
; /* max value */
268 size_t bofs
; /* bit offset */
271 struct cyttsp4_sysinfo_ofs
{
277 size_t num_btn_regs
; /* ceil(num_btns/4) */
286 size_t x_origin
; /* left or right corner */
288 size_t y_origin
; /* upper or lower corner */
302 size_t btn_keys_size
;
303 struct cyttsp4_tch_abs_params tch_abs
[CY_TCH_NUM_ABS
];
304 size_t btn_rec_size
; /* btn record size (in bytes) */
305 size_t btn_diff_ofs
;/* btn data loc ,diff counts, (Op-Mode byte ofs) */
306 size_t btn_diff_size
;/* btn size of diff counts (in bits) */
309 enum cyttsp4_btn_state
{
317 int state
; /* CY_BTN_PRESSED, CY_BTN_RELEASED */
321 struct cyttsp4_sysinfo
{
323 struct cyttsp4_sysinfo_data si_data
;
324 struct cyttsp4_sysinfo_ptr si_ptrs
;
325 struct cyttsp4_sysinfo_ofs si_ofs
;
326 struct cyttsp4_btn
*btn
; /* button states */
327 u8
*btn_rec_data
; /* button diff count data */
328 u8
*xy_mode
; /* operational mode and status regs */
329 u8
*xy_data
; /* operational touch regs */
332 struct cyttsp4_mt_data
{
333 struct cyttsp4_mt_platform_data
*pdata
;
334 struct cyttsp4_sysinfo
*si
;
335 struct input_dev
*input
;
336 struct mutex report_lock
;
344 struct mutex system_lock
;
345 struct mutex adap_lock
;
346 enum cyttsp4_mode mode
;
347 enum cyttsp4_sleep_state sleep_state
;
348 enum cyttsp4_startup_state startup_state
;
350 wait_queue_head_t wait_q
;
352 struct work_struct startup_work
;
353 struct work_struct watchdog_work
;
354 struct timer_list watchdog_timer
;
355 struct cyttsp4_sysinfo sysinfo
;
359 bool invalid_touch_app
;
360 struct cyttsp4_mt_data md
;
361 struct cyttsp4_platform_data
*pdata
;
362 struct cyttsp4_core_platform_data
*cpdata
;
363 const struct cyttsp4_bus_ops
*bus_ops
;
366 u8 pr_buf
[CY_MAX_PRBUF_SIZE
];
370 struct cyttsp4_bus_ops
{
372 int (*write
)(struct device
*dev
, u8
*xfer_buf
, u16 addr
, u8 length
,
374 int (*read
)(struct device
*dev
, u8
*xfer_buf
, u16 addr
, u8 length
,
378 enum cyttsp4_hst_mode_bits
{
379 CY_HST_TOGGLE
= (1 << 7),
380 CY_HST_MODE_CHANGE
= (1 << 3),
381 CY_HST_MODE
= (7 << 4),
382 CY_HST_OPERATE
= (0 << 4),
383 CY_HST_SYSINFO
= (1 << 4),
384 CY_HST_CAT
= (2 << 4),
385 CY_HST_LOWPOW
= (1 << 2),
386 CY_HST_SLEEP
= (1 << 1),
387 CY_HST_RESET
= (1 << 0),
391 #define CY_IGNORE_VALUE 0xFFFF
393 /* abs signal capabilities offsets in the frameworks array */
394 enum cyttsp4_sig_caps
{
400 CY_NUM_ABS_SET
/* number of signal capability fields */
403 /* abs axis signal offsets in the framworks array */
404 enum cyttsp4_sig_ost
{
413 CY_NUM_ABS_OST
/* number of abs signals */
418 CY_FLAG_HOVER
= 0x04,
420 CY_FLAG_INV_X
= 0x10,
421 CY_FLAG_INV_Y
= 0x20,
422 CY_FLAG_VKEYS
= 0x40,
425 enum cyttsp4_object_id
{
426 CY_OBJ_STANDARD_FINGER
,
432 enum cyttsp4_event_id
{
435 CY_EV_MOVE
, /* significant displacement (> act dist) */
436 CY_EV_LIFTOFF
, /* record reports last position */
439 /* x-axis resolution of panel in pixels */
440 #define CY_PCFG_RESOLUTION_X_MASK 0x7F
442 /* y-axis resolution of panel in pixels */
443 #define CY_PCFG_RESOLUTION_Y_MASK 0x7F
445 /* x-axis, 0:origin is on left side of panel, 1: right */
446 #define CY_PCFG_ORIGIN_X_MASK 0x80
448 /* y-axis, 0:origin is on top side of panel, 1: bottom */
449 #define CY_PCFG_ORIGIN_Y_MASK 0x80
451 static inline int cyttsp4_adap_read(struct cyttsp4
*ts
, u16 addr
, int size
,
454 return ts
->bus_ops
->read(ts
->dev
, ts
->xfer_buf
, addr
, size
, buf
);
457 static inline int cyttsp4_adap_write(struct cyttsp4
*ts
, u16 addr
, int size
,
460 return ts
->bus_ops
->write(ts
->dev
, ts
->xfer_buf
, addr
, size
, buf
);
463 extern struct cyttsp4
*cyttsp4_probe(const struct cyttsp4_bus_ops
*ops
,
464 struct device
*dev
, u16 irq
, size_t xfer_buf_size
);
465 extern int cyttsp4_remove(struct cyttsp4
*ts
);
466 int cyttsp_i2c_write_block_data(struct device
*dev
, u8
*xfer_buf
, u16 addr
,
467 u8 length
, const void *values
);
468 int cyttsp_i2c_read_block_data(struct device
*dev
, u8
*xfer_buf
, u16 addr
,
469 u8 length
, void *values
);
470 extern const struct dev_pm_ops cyttsp4_pm_ops
;
472 #endif /* _LINUX_CYTTSP4_CORE_H */