1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 
3 #ifndef _TOUCH_OFFLOAD_H
4 #define _TOUCH_OFFLOAD_H
5 
6 #define TOUCH_OFFLOAD_MAGIC '7'
7 
8 /* Bus interface type */
9 #define BUS_TYPE_I2C 0
10 #define BUS_TYPE_SPI 1
11 #define BUS_TYPE_I3C 2
12 
13 /* Indicates full heatmap frame vs. partial */
14 #define HEATMAP_SIZE_PARTIAL  0
15 #define HEATMAP_SIZE_FULL     1
16 
17 /* Touch channel data types */
18 #define TOUCH_DATA_TYPE_COORD	  0x01
19 #define TOUCH_DATA_TYPE_RAW	  0x02
20 #define TOUCH_DATA_TYPE_FILTERED  0x04
21 #define TOUCH_DATA_TYPE_BASELINE  0x08
22 #define TOUCH_DATA_TYPE_STRENGTH  0x10
23 
24 /* Touch channel scan types */
25 #define TOUCH_SCAN_TYPE_MUTUAL	  0x40
26 #define TOUCH_SCAN_TYPE_SELF	  0x80
27 
28 
29 //////////////////////////////////////////////////////////////
30 
31 /* TouchOffloadCaps
32  *
33  * touch_offload_major_version - Major version for breaking changes
34  * touch_offload_minor_version - Minor version for small, compatible changes
35  * device_id - device-specific identifier
36  * display_width - width of device display in pixels
37  * display_height - height of device display in pixels
38  * tx_size - number of TX channels
39  * rx_size - number of RX channels
40  * bus_type - bus interface type
41  * bus_speed_hz - bus frequency
42  * heatmap_size - partial or full heatmap
43  * touch_data_scan_types - channel data types available
44  * touch_scan_types - channel scan types available
45  * continuous_reporting - driver supports continuous touch reports
46  * noise_reporting - driver supports noise status messages
47  * cancel_reporting - driver supports sending cancel events
48  * size_reporting - driver supports size information
49  * filter_grip - driver supports disabling underlying grip suppression
50  * filter_palm - driver supports disabling underlying palm rejection
51  * num_sensitivity_settings - number of sensitivity options provided
52  */
53 struct TouchOffloadCaps {
54 	/* Version info */
55 	__u32 touch_offload_major_version;
56 	__u32 touch_offload_minor_version;
57 	__u8 reserved1[8];
58 
59 	/* Device info */
60 	__u32 device_id;
61 	__u16 display_width;
62 	__u16 display_height;
63 	__u16 tx_size;
64 	__u16 rx_size;
65 	__u8 bus_type;
66 	__u32 bus_speed_hz;
67 	__u8 reserved2[16];
68 
69 	/* Algorithm info */
70 	__u8 heatmap_size;
71 	__u16 touch_data_types;
72 	__u16 touch_scan_types;
73 	__u8 reserved3[16];
74 
75 	/* Feature flags */
76 	__u8 continuous_reporting;
77 	__u8 noise_reporting;
78 	__u8 cancel_reporting;
79 	__u8 size_reporting;
80 	__u8 filter_grip;
81 	__u8 filter_palm;
82 	__u8 num_sensitivity_settings;
83 	__u8 reserved4[32];
84 };
85 
86 /* TouchOffloadConfig
87  *
88  * continuous_reporting - enable continuous touch reports
89  * noise_reporting - enable noise status messages
90  * cancel_reporting - enable cancel events
91  * filter_grip - enable underlying grip suppression
92  * filter_palm - enable underlying palm rejection
93  * num_sensitivity_settings - number of sensitivity options provided
94  * read_coords - allocate a channel to coordinate data
95  * mutual_data_types - bitfield of mutual data types to collect
96  * self_data_types - bitfield of self data types to collect
97  */
98 struct TouchOffloadConfig {
99 	/* Feature flags */
100 	__u8 continuous_reporting;
101 	__u8 noise_reporting;
102 	__u8 cancel_reporting;
103 	__u8 filter_grip;
104 	__u8 filter_palm;
105 	__u8 sensitivity_setting;
106 	__u8 reserved1[16];
107 
108 	/* Data to read */
109 	__u8 read_coords;
110 	__u16 mutual_data_types;
111 	__u16 self_data_types;
112 	__u8 reserved2[16];
113 };
114 
115 /* TouchOffloadFrameHeader
116  *
117  * frame_size - number of bytes in the frame
118  * index - unique, sequential frame index
119  * timestamp - frame timestamp in nanoseconds
120  * num_channels - number of channels included in the frame
121  */
122 struct TouchOffloadFrameHeader {
123 	__u32 frame_size;
124 	__u64 index;
125 	__u64 timestamp;
126 	__u8 num_channels;
127 } __attribute__((packed));
128 
129 /* TouchOffloadChannelHeader
130  *
131  * channel_type - touch type stored in the channel
132  * channel_size - size in bytes of the channel sample
133  */
134 struct TouchOffloadChannelHeader {
135 	__u8 channel_type;
136 	__u32 channel_size;
137 } __attribute__((packed));
138 
139 /* CoordStatus
140  *
141  * COORD_STATUS_INACTIVE - slot is unused
142  * COORD_STATUS_FINGER - normal finger touch
143  * COORD_STATUS_EDGE - edge touch
144  * COORD_STATUS_PALM - palm touch
145  * COORD_STATUS_CANCEL - canceled touch
146  */
147 enum CoordStatus {
148 	COORD_STATUS_INACTIVE = 0x00,
149 	COORD_STATUS_FINGER = 0x01,
150 	COORD_STATUS_EDGE = 0x02,
151 	COORD_STATUS_PALM = 0x03,
152 	COORD_STATUS_CANCEL = 0x04
153 };
154 
155 /* Maximum number of touches that are tracked simultaneously */
156 #define MAX_COORDS 10
157 
158 /* TouchOffloadCoord
159  *
160  * x - x component of touch location
161  * y - y component of touch location
162  * status - type of touch
163  * major - size of the larger axis of the touch blob
164  * minor - size of the smaller axis of the touch blob
165  * pressure - z-axis or force exerted on touch touch point
166  */
167 struct TouchOffloadCoord {
168 	__u16 x;
169 	__u16 y;
170 	enum CoordStatus status;
171 	__u32 major;
172 	__u32 minor;
173 	__u32 pressure;
174 	__u8 reserved1[16];
175 } __attribute__((packed));
176 
177 /* TouchOffloadDataCoord
178  *
179  * header - header shared by all channels in a frame
180  * coords - array of MAX_COORD coordinates
181  */
182 struct TouchOffloadDataCoord {
183 	struct TouchOffloadChannelHeader header;
184 	struct TouchOffloadCoord coords[MAX_COORDS];
185 	__u8 reserved1[16];
186 } __attribute__((packed));
187 #define TOUCH_OFFLOAD_FRAME_SIZE_COORD (sizeof(struct TouchOffloadDataCoord))
188 
189 /* TouchOffloadData2d
190  *
191  * header - header shared by all channels in a frame
192  * tx_size - number of tx channels
193  * rx_size - number of rx channels
194  * data - pointer to raw touch data buffer
195  */
196 struct TouchOffloadData2d {
197 	struct TouchOffloadChannelHeader header;
198 	__u16 tx_size;
199 	__u16 rx_size;
200 	__u8 reserved1[16];
201 	__u8 data[1];
202 } __attribute__((packed));
203 #define TOUCH_OFFLOAD_DATA_SIZE_2D(rx, tx) (sizeof(__u16)*(rx)*(tx))
204 #define TOUCH_OFFLOAD_FRAME_SIZE_2D(rx, tx) \
205 	(sizeof(struct TouchOffloadData2d) - 1 + \
206 	TOUCH_OFFLOAD_DATA_SIZE_2D((rx), (tx)))
207 
208 /* TouchOffloadData1d
209  *
210  * header - header shared by all channels in a frame
211  * tx_size - number of tx channels
212  * rx_size - number of rx channels
213  * data - pointer to raw touch data buffer
214  */
215 struct TouchOffloadData1d {
216 	struct TouchOffloadChannelHeader header;
217 	__u16 tx_size;
218 	__u16 rx_size;
219 	__u8 reserved1[16];
220 	__u8 data[1];
221 } __attribute__((packed));
222 #define TOUCH_OFFLOAD_DATA_SIZE_1D(rx, tx) (sizeof(__u16)*((rx)+(tx)))
223 #define TOUCH_OFFLOAD_FRAME_SIZE_1D(rx, tx) \
224 	(sizeof(struct TouchOffloadData1d) - 1 + \
225 	TOUCH_OFFLOAD_DATA_SIZE_1D((rx), (tx)))
226 
227 ////////////////////////////////////////////////////////////
228 
229 /* TouchOffloadIocGetCaps
230  *
231  * caps - capabilities provided by the touch driver
232  */
233 struct TouchOffloadIocGetCaps {
234 	struct TouchOffloadCaps caps;
235 	__u8 reserved1[16];
236 };
237 
238 /* TouchOffloadIocConfigure
239  *
240  * config - features to be used by the touch_offload client
241  */
242 struct TouchOffloadIocConfigure {
243 	struct TouchOffloadConfig config;
244 	__u8 reserved1[16];
245 };
246 
247 /* TouchOffloadIocReport
248  *
249  * index - unique, sequential frame index
250  * timestamp - frame timestamp in nanoseconds
251  * num_coords - number of coordinates contained in "coords"
252  * coords - array of coordinates to be reported to the driver
253  */
254 struct TouchOffloadIocReport {
255 	__u64 index;
256 	__u64 timestamp;
257 	__u8 num_coords;
258 	__u8 reserved1[16];
259 	struct TouchOffloadCoord coords[MAX_COORDS];
260 };
261 
262 /* Ioctl to retrieve the capabilities of the touch driver */
263 #define TOUCH_OFFLOAD_IOC_RD_GETCAPS \
264 	_IOR(TOUCH_OFFLOAD_MAGIC, 0, struct TouchOffloadIocGetCaps)
265 
266 /* Ioctl to set the configuration of the touch driver */
267 #define TOUCH_OFFLOAD_IOC_WR_CONFIGURE \
268 	_IOW(TOUCH_OFFLOAD_MAGIC, 1, struct TouchOffloadIocConfigure)
269 
270 /* Ioctl to start the touch_offload pipeline */
271 #define TOUCH_OFFLOAD_IOC_START _IOC(TOUCH_OFFLOAD_MAGIC, 2)
272 
273 /* Ioctl to report coordinates to the driver */
274 #define TOUCH_OFFLOAD_IOC_WR_REPORT \
275 	_IOW(TOUCH_OFFLOAD_MAGIC, 3, struct TouchOffloadIocReport)
276 
277 /* Ioctl to stop the touch_offload pipeline */
278 #define TOUCH_OFFLOAD_IOC_STOP _IOC(TOUCH_OFFLOAD_MAGIC, 4)
279 
280 #endif /* _TOUCH_OFFLOAD_H */
281