1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Header file for:
4  * Cypress TrueTouch(TM) Standard Product (TTSP) touchscreen drivers.
5  * For use with Cypress Txx3xx parts.
6  * Supported parts include:
7  * CY8CTST341
8  * CY8CTMA340
9  *
10  * Copyright (C) 2009, 2010, 2011 Cypress Semiconductor, Inc.
11  * Copyright (C) 2012 Javier Martinez Canillas <javier@dowhile0.org>
12  *
13  * Contact Cypress Semiconductor at www.cypress.com <kev@cypress.com>
14  */
15 
16 
17 #ifndef __CYTTSP_CORE_H__
18 #define __CYTTSP_CORE_H__
19 
20 #include <linux/kernel.h>
21 #include <linux/err.h>
22 #include <linux/module.h>
23 #include <linux/types.h>
24 #include <linux/device.h>
25 #include <linux/input/cyttsp.h>
26 
27 #define CY_NUM_RETRY		16 /* max number of retries for read ops */
28 
29 struct cyttsp_tch {
30 	__be16 x, y;
31 	u8 z;
32 } __packed;
33 
34 /* TrueTouch Standard Product Gen3 interface definition */
35 struct cyttsp_xydata {
36 	u8 hst_mode;
37 	u8 tt_mode;
38 	u8 tt_stat;
39 	struct cyttsp_tch tch1;
40 	u8 touch12_id;
41 	struct cyttsp_tch tch2;
42 	u8 gest_cnt;
43 	u8 gest_id;
44 	struct cyttsp_tch tch3;
45 	u8 touch34_id;
46 	struct cyttsp_tch tch4;
47 	u8 tt_undef[3];
48 	u8 act_dist;
49 	u8 tt_reserved;
50 } __packed;
51 
52 
53 /* TTSP System Information interface definition */
54 struct cyttsp_sysinfo_data {
55 	u8 hst_mode;
56 	u8 mfg_stat;
57 	u8 mfg_cmd;
58 	u8 cid[3];
59 	u8 tt_undef1;
60 	u8 uid[8];
61 	u8 bl_verh;
62 	u8 bl_verl;
63 	u8 tts_verh;
64 	u8 tts_verl;
65 	u8 app_idh;
66 	u8 app_idl;
67 	u8 app_verh;
68 	u8 app_verl;
69 	u8 tt_undef[5];
70 	u8 scn_typ;
71 	u8 act_intrvl;
72 	u8 tch_tmout;
73 	u8 lp_intrvl;
74 };
75 
76 /* TTSP Bootloader Register Map interface definition */
77 #define CY_BL_CHKSUM_OK 0x01
78 struct cyttsp_bootloader_data {
79 	u8 bl_file;
80 	u8 bl_status;
81 	u8 bl_error;
82 	u8 blver_hi;
83 	u8 blver_lo;
84 	u8 bld_blver_hi;
85 	u8 bld_blver_lo;
86 	u8 ttspver_hi;
87 	u8 ttspver_lo;
88 	u8 appid_hi;
89 	u8 appid_lo;
90 	u8 appver_hi;
91 	u8 appver_lo;
92 	u8 cid_0;
93 	u8 cid_1;
94 	u8 cid_2;
95 };
96 
97 struct cyttsp;
98 
99 struct cyttsp_bus_ops {
100 	u16 bustype;
101 	int (*write)(struct device *dev, u8 *xfer_buf, u16 addr, u8 length,
102 			const void *values);
103 	int (*read)(struct device *dev, u8 *xfer_buf, u16 addr, u8 length,
104 			void *values);
105 };
106 
107 enum cyttsp_state {
108 	CY_IDLE_STATE,
109 	CY_ACTIVE_STATE,
110 	CY_BL_STATE,
111 };
112 
113 struct cyttsp {
114 	struct device *dev;
115 	int irq;
116 	struct input_dev *input;
117 	char phys[32];
118 	const struct cyttsp_bus_ops *bus_ops;
119 	struct cyttsp_bootloader_data bl_data;
120 	struct cyttsp_sysinfo_data sysinfo_data;
121 	struct cyttsp_xydata xy_data;
122 	struct completion bl_ready;
123 	enum cyttsp_state state;
124 	bool suspended;
125 
126 	struct gpio_desc *reset_gpio;
127 	bool use_hndshk;
128 	u8 act_dist;
129 	u8 act_intrvl;
130 	u8 tch_tmout;
131 	u8 lp_intrvl;
132 	u8 *bl_keys;
133 
134 	u8 xfer_buf[] ____cacheline_aligned;
135 };
136 
137 struct cyttsp *cyttsp_probe(const struct cyttsp_bus_ops *bus_ops,
138 			    struct device *dev, int irq, size_t xfer_buf_size);
139 
140 int cyttsp_i2c_write_block_data(struct device *dev, u8 *xfer_buf, u16 addr,
141 		u8 length, const void *values);
142 int cyttsp_i2c_read_block_data(struct device *dev, u8 *xfer_buf, u16 addr,
143 		u8 length, void *values);
144 extern const struct dev_pm_ops cyttsp_pm_ops;
145 
146 #endif /* __CYTTSP_CORE_H__ */
147