Commit | Line | Data |
---|---|---|
6fa3eb70 S |
1 | /* |
2 | * Synaptics DSX touchscreen driver | |
3 | * | |
4 | * Copyright (C) 2012 Synaptics Incorporated | |
5 | * | |
6 | * Copyright (C) 2012 Alexandra Chin <alexandra.chin@tw.synaptics.com> | |
7 | * Copyright (C) 2012 Scott Lin <scott.lin@tw.synaptics.com> | |
8 | * Copyright (C) 2010 Js HA <js.ha@stericsson.com> | |
9 | * Copyright (C) 2010 Naveen Kumar G <naveen.gaddipati@stericsson.com> | |
10 | * | |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License as published by | |
13 | * the Free Software Foundation; either version 2 of the License, or | |
14 | * (at your option) any later version. | |
15 | * | |
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. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License | |
22 | * along with this program; if not, write to the Free Software | |
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 | */ | |
25 | #ifndef _SYNAPTICS_DSX_RMI4_H_ | |
26 | #define _SYNAPTICS_DSX_RMI4_H_ | |
27 | ||
28 | #define SYNAPTICS_RMI4_DRIVER_VERSION "1.0" | |
29 | ||
30 | #define PROXIMITY 0 | |
31 | ||
32 | #define PDT_PROPS (0X00EF) | |
33 | #define PDT_START (0x00E9) | |
34 | #define PDT_END (0x000A) | |
35 | #define PDT_ENTRY_SIZE (0x0006) | |
36 | #define PAGES_TO_SERVICE (10) | |
37 | #define PAGE_SELECT_LEN (2) | |
38 | ||
39 | #define SYNAPTICS_RMI4_F01 (0x01) | |
40 | #define SYNAPTICS_RMI4_F11 (0x11) | |
41 | #define SYNAPTICS_RMI4_F12 (0x12) | |
42 | #define SYNAPTICS_RMI4_F1A (0x1a) | |
43 | #define SYNAPTICS_RMI4_F34 (0x34) | |
44 | #define SYNAPTICS_RMI4_F51 (0x51) | |
45 | #define SYNAPTICS_RMI4_F54 (0x54) | |
46 | ||
47 | #define SYNAPTICS_RMI4_PRODUCT_INFO_SIZE 2 | |
48 | #define SYNAPTICS_RMI4_PRODUCT_ID_LENGTH 10 | |
49 | ||
50 | #define MAX_NUMBER_OF_FINGERS 10 | |
51 | #define MAX_NUMBER_OF_BUTTONS 4 | |
52 | #define MAX_INTR_REGISTERS 4 | |
53 | ||
54 | #define MASK_16BIT 0xFFFF | |
55 | #define MASK_8BIT 0xFF | |
56 | #define MASK_7BIT 0x7F | |
57 | #define MASK_6BIT 0x3F | |
58 | #define MASK_5BIT 0x1F | |
59 | #define MASK_4BIT 0x0F | |
60 | #define MASK_3BIT 0x07 | |
61 | #define MASK_2BIT 0x03 | |
62 | #define MASK_1BIT 0x01 | |
63 | ||
64 | #define NO_0D_WHILE_2D 1 | |
65 | ||
66 | #define RPT_OBJ_TYPE (1 << 0) | |
67 | #define RPT_X_LSB (1 << 1) | |
68 | #define RPT_X_MSB (1 << 2) | |
69 | #define RPT_Y_LSB (1 << 3) | |
70 | #define RPT_Y_MSB (1 << 4) | |
71 | #define RPT_Z (1 << 5) | |
72 | #define RPT_WX (1 << 6) | |
73 | #define RPT_WY (1 << 7) | |
74 | #define F12_RPT_DEFAULT (RPT_OBJ_TYPE | RPT_X_LSB | RPT_Y_LSB | RPT_Y_MSB) | |
75 | #define F12_RPT (F12_RPT_DEFAULT | RPT_WX | RPT_WY) | |
76 | ||
77 | #if PROXIMITY | |
78 | #define HOVER_Z_MAX 255 | |
79 | #define FINGER_HOVER (1 << 0) | |
80 | #define AIR_SWIPE (1 << 1) | |
81 | #define LARGE_OBJ (1 << 2) | |
82 | #define HOVER_PINCH (1 << 3) | |
83 | #define NO_PROXIMITY_ON_TOUCH (1 << 5) | |
84 | #define PROXIMITY_ENABLE (FINGER_HOVER | NO_PROXIMITY_ON_TOUCH) | |
85 | #endif | |
86 | ||
87 | #define EXP_FN_DET_INTERVAL 1000 /* ms */ | |
88 | #define POLLING_PERIOD 1 /* ms */ | |
89 | #define SYN_I2C_RETRY_TIMES 10 | |
90 | #define MAX_TOUCH_MAJOR 15 | |
91 | ||
92 | #define F01_STD_QUERY_LEN 21 | |
93 | #define F11_STD_QUERY_LEN 9 | |
94 | #define F11_STD_CTRL_LEN 10 | |
95 | #define F11_STD_DATA_LEN 12 | |
96 | ||
97 | #define NORMAL_OPERATION (0 << 0) | |
98 | #define SENSOR_SLEEP (1 << 0) | |
99 | #define NO_SLEEP_OFF (0 << 3) | |
100 | #define NO_SLEEP_ON (1 << 3) | |
101 | ||
102 | enum exp_fn { | |
103 | RMI_DEV = 0, | |
104 | RMI_F34, | |
105 | RMI_F54, | |
106 | RMI_FW_UPDATER, | |
107 | RMI_LAST, | |
108 | }; | |
109 | ||
110 | ||
111 | struct synaptics_rmi4_f12_query_5 { | |
112 | union { | |
113 | struct { | |
114 | unsigned char size_of_query6; | |
115 | struct { | |
116 | unsigned char ctrl0_is_present:1; | |
117 | unsigned char ctrl1_is_present:1; | |
118 | unsigned char ctrl2_is_present:1; | |
119 | unsigned char ctrl3_is_present:1; | |
120 | unsigned char ctrl4_is_present:1; | |
121 | unsigned char ctrl5_is_present:1; | |
122 | unsigned char ctrl6_is_present:1; | |
123 | unsigned char ctrl7_is_present:1; | |
124 | } __packed; | |
125 | struct { | |
126 | unsigned char ctrl8_is_present:1; | |
127 | unsigned char ctrl9_is_present:1; | |
128 | unsigned char ctrl10_is_present:1; | |
129 | unsigned char ctrl11_is_present:1; | |
130 | unsigned char ctrl12_is_present:1; | |
131 | unsigned char ctrl13_is_present:1; | |
132 | unsigned char ctrl14_is_present:1; | |
133 | unsigned char ctrl15_is_present:1; | |
134 | } __packed; | |
135 | struct { | |
136 | unsigned char ctrl16_is_present:1; | |
137 | unsigned char ctrl17_is_present:1; | |
138 | unsigned char ctrl18_is_present:1; | |
139 | unsigned char ctrl19_is_present:1; | |
140 | unsigned char ctrl20_is_present:1; | |
141 | unsigned char ctrl21_is_present:1; | |
142 | unsigned char ctrl22_is_present:1; | |
143 | unsigned char ctrl23_is_present:1; | |
144 | } __packed; | |
145 | }; | |
146 | unsigned char data[4]; | |
147 | }; | |
148 | }; | |
149 | ||
150 | struct synaptics_rmi4_f12_query_8 { | |
151 | union { | |
152 | struct { | |
153 | unsigned char size_of_query9; | |
154 | struct { | |
155 | unsigned char data0_is_present:1; | |
156 | unsigned char data1_is_present:1; | |
157 | unsigned char data2_is_present:1; | |
158 | unsigned char data3_is_present:1; | |
159 | unsigned char data4_is_present:1; | |
160 | unsigned char data5_is_present:1; | |
161 | unsigned char data6_is_present:1; | |
162 | unsigned char data7_is_present:1; | |
163 | } __packed; | |
164 | }; | |
165 | unsigned char data[2]; | |
166 | }; | |
167 | }; | |
168 | ||
169 | struct synaptics_rmi4_f12_ctrl_8 { | |
170 | union { | |
171 | struct { | |
172 | unsigned char max_x_coord_lsb; | |
173 | unsigned char max_x_coord_msb; | |
174 | unsigned char max_y_coord_lsb; | |
175 | unsigned char max_y_coord_msb; | |
176 | unsigned char rx_pitch_lsb; | |
177 | unsigned char rx_pitch_msb; | |
178 | unsigned char tx_pitch_lsb; | |
179 | unsigned char tx_pitch_msb; | |
180 | unsigned char low_rx_clip; | |
181 | unsigned char high_rx_clip; | |
182 | unsigned char low_tx_clip; | |
183 | unsigned char high_tx_clip; | |
184 | unsigned char num_of_rx; | |
185 | unsigned char num_of_tx; | |
186 | }; | |
187 | unsigned char data[14]; | |
188 | }; | |
189 | }; | |
190 | ||
191 | struct synaptics_rmi4_f12_ctrl_23 { | |
192 | union { | |
193 | struct { | |
194 | unsigned char obj_type_enable; | |
195 | unsigned char max_reported_objects; | |
196 | }; | |
197 | unsigned char data[2]; | |
198 | }; | |
199 | }; | |
200 | ||
201 | struct synaptics_rmi4_f12_finger_data { | |
202 | union { | |
203 | struct { | |
204 | unsigned char object_type_and_status; | |
205 | unsigned char x_lsb; | |
206 | unsigned char x_msb; | |
207 | unsigned char y_lsb; | |
208 | unsigned char y_msb; | |
209 | unsigned char z; | |
210 | unsigned char wx; | |
211 | unsigned char wy; | |
212 | }; | |
213 | unsigned char data[8]; | |
214 | }; | |
215 | }; | |
216 | ||
217 | struct synaptics_rmi4_f1a_query { | |
218 | union { | |
219 | struct { | |
220 | unsigned char max_button_count:3; | |
221 | unsigned char reserved:5; | |
222 | unsigned char has_general_control:1; | |
223 | unsigned char has_interrupt_enable:1; | |
224 | unsigned char has_multibutton_select:1; | |
225 | unsigned char has_tx_rx_map:1; | |
226 | unsigned char has_perbutton_threshold:1; | |
227 | unsigned char has_release_threshold:1; | |
228 | unsigned char has_strongestbtn_hysteresis:1; | |
229 | unsigned char has_filter_strength:1; | |
230 | } __packed; | |
231 | unsigned char data[2]; | |
232 | }; | |
233 | }; | |
234 | ||
235 | struct synaptics_rmi4_f1a_control_0 { | |
236 | union { | |
237 | struct { | |
238 | unsigned char multibutton_report:2; | |
239 | unsigned char filter_mode:2; | |
240 | unsigned char reserved:4; | |
241 | } __packed; | |
242 | unsigned char data[1]; | |
243 | }; | |
244 | }; | |
245 | ||
246 | struct synaptics_rmi4_f1a_control_3_4 { | |
247 | unsigned char transmitterbutton; | |
248 | unsigned char receiverbutton; | |
249 | }; | |
250 | ||
251 | struct synaptics_rmi4_f1a_control { | |
252 | struct synaptics_rmi4_f1a_control_0 general_control; | |
253 | unsigned char *button_int_enable; | |
254 | unsigned char *multi_button; | |
255 | struct synaptics_rmi4_f1a_control_3_4 *electrode_map; | |
256 | unsigned char *button_threshold; | |
257 | unsigned char button_release_threshold; | |
258 | unsigned char strongest_button_hysteresis; | |
259 | unsigned char filter_strength; | |
260 | }; | |
261 | ||
262 | struct synaptics_rmi4_f1a_handle { | |
263 | int button_bitmask_size; | |
264 | unsigned char button_count; | |
265 | unsigned char valid_button_count; | |
266 | unsigned char *button_data_buffer; | |
267 | unsigned char *button_map; | |
268 | struct synaptics_rmi4_f1a_query button_query; | |
269 | struct synaptics_rmi4_f1a_control button_control; | |
270 | }; | |
271 | ||
272 | #if PROXIMITY | |
273 | struct synaptics_rmi4_f51_query { | |
274 | union { | |
275 | struct { | |
276 | unsigned char query_register_count; | |
277 | unsigned char data_register_count; | |
278 | unsigned char control_register_count; | |
279 | unsigned char command_register_count; | |
280 | }; | |
281 | unsigned char data[4]; | |
282 | }; | |
283 | }; | |
284 | ||
285 | struct synaptics_rmi4_f51_data { | |
286 | union { | |
287 | struct { | |
288 | unsigned char finger_hover_det:1; | |
289 | unsigned char air_swipe_det:1; | |
290 | unsigned char large_obj_det:1; | |
291 | unsigned char f1a_data0_b3:1; | |
292 | unsigned char hover_pinch_det:1; | |
293 | unsigned char f1a_data0_b5__7:3; | |
294 | unsigned char hover_finger_x_4__11; | |
295 | unsigned char hover_finger_y_4__11; | |
296 | unsigned char hover_finger_xy_0__3; | |
297 | unsigned char hover_finger_z; | |
298 | unsigned char f1a_data2_b0__6:7; | |
299 | unsigned char hover_pinch_dir:1; | |
300 | unsigned char air_swipe_dir_0:1; | |
301 | unsigned char air_swipe_dir_1:1; | |
302 | unsigned char f1a_data3_b2__5:4; | |
303 | unsigned char large_obj_act:2; | |
304 | } __packed; | |
305 | unsigned char data[7]; | |
306 | }; | |
307 | }; | |
308 | ||
309 | struct synaptics_rmi4_f51_handle { | |
310 | unsigned short proximity_enables_addr; | |
311 | struct synaptics_rmi4_data *rmi4_data; | |
312 | }; | |
313 | #endif | |
314 | ||
315 | ||
316 | ||
317 | struct synaptics_rmi4_exp_fn { | |
318 | enum exp_fn fn_type; | |
319 | bool inserted; | |
320 | int (*func_init)(struct i2c_client *client); | |
321 | void (*func_remove)(struct i2c_client *client); | |
322 | void (*func_attn)(struct i2c_client *client, | |
323 | unsigned char intr_mask); | |
324 | struct list_head link; | |
325 | }; | |
326 | ||
327 | ||
328 | /* | |
329 | * struct synaptics_rmi4_fn_desc - function descriptor fields in PDT | |
330 | * @query_base_addr: base address for query registers | |
331 | * @cmd_base_addr: base address for command registers | |
332 | * @ctrl_base_addr: base address for control registers | |
333 | * @data_base_addr: base address for data registers | |
334 | * @intr_src_count: number of interrupt sources | |
335 | * @fn_number: function number | |
336 | */ | |
337 | struct synaptics_rmi4_fn_desc { | |
338 | unsigned char query_base_addr; | |
339 | unsigned char cmd_base_addr; | |
340 | unsigned char ctrl_base_addr; | |
341 | unsigned char data_base_addr; | |
342 | unsigned char intr_src_count; | |
343 | unsigned char fn_number; | |
344 | }; | |
345 | ||
346 | /* | |
347 | * synaptics_rmi4_fn_full_addr - full 16-bit base addresses | |
348 | * @query_base: 16-bit base address for query registers | |
349 | * @cmd_base: 16-bit base address for data registers | |
350 | * @ctrl_base: 16-bit base address for command registers | |
351 | * @data_base: 16-bit base address for control registers | |
352 | */ | |
353 | struct synaptics_rmi4_fn_full_addr { | |
354 | unsigned short query_base; | |
355 | unsigned short cmd_base; | |
356 | unsigned short ctrl_base; | |
357 | unsigned short data_base; | |
358 | }; | |
359 | ||
360 | /* | |
361 | * struct synaptics_rmi4_fn - function handler data structure | |
362 | * @fn_number: function number | |
363 | * @num_of_data_sources: number of data sources | |
364 | * @num_of_data_points: maximum number of fingers supported | |
365 | * @size_of_data_register_block: data register block size | |
366 | * @data1_offset: offset to data1 register from data base address | |
367 | * @intr_reg_num: index to associated interrupt register | |
368 | * @intr_mask: interrupt mask | |
369 | * @full_addr: full 16-bit base addresses of function registers | |
370 | * @link: linked list for function handlers | |
371 | * @data_size: size of private data | |
372 | * @data: pointer to private data | |
373 | */ | |
374 | struct synaptics_rmi4_fn { | |
375 | unsigned char fn_number; | |
376 | unsigned char num_of_data_sources; | |
377 | unsigned char num_of_data_points; | |
378 | unsigned char size_of_data_register_block; | |
379 | unsigned char data1_offset; | |
380 | unsigned char intr_reg_num; | |
381 | unsigned char intr_mask; | |
382 | struct synaptics_rmi4_fn_full_addr full_addr; | |
383 | struct list_head link; | |
384 | int data_size; | |
385 | void *data; | |
386 | }; | |
387 | ||
388 | ||
389 | /* | |
390 | * struct synaptics_rmi4_device_info - device information | |
391 | * @version_major: rmi protocol major version number | |
392 | * @version_minor: rmi protocol minor version number | |
393 | * @manufacturer_id: manufacturer id | |
394 | * @product_props: product properties information | |
395 | * @product_info: product info array | |
396 | * @date_code: device manufacture date | |
397 | * @tester_id: tester id array | |
398 | * @serial_number: device serial number | |
399 | * @product_id_string: device product id | |
400 | * @support_fn_list: linked list for function handlers | |
401 | */ | |
402 | struct synaptics_rmi4_device_info { | |
403 | unsigned int version_major; | |
404 | unsigned int version_minor; | |
405 | unsigned char manufacturer_id; | |
406 | unsigned char product_props; | |
407 | unsigned char product_info[2]; | |
408 | unsigned char date_code[3]; | |
409 | unsigned short tester_id; | |
410 | unsigned short serial_number; | |
411 | unsigned char product_id_string[11]; | |
412 | struct list_head support_fn_list; | |
413 | }; | |
414 | ||
415 | struct synaptics_rmi4_f01_device_status { | |
416 | union { | |
417 | struct { | |
418 | unsigned char status_code:4; | |
419 | unsigned char reserved:2; | |
420 | unsigned char flash_prog:1; | |
421 | unsigned char unconfigured:1; | |
422 | } __packed; | |
423 | unsigned char data[1]; | |
424 | }; | |
425 | }; | |
426 | ||
427 | ||
428 | ||
429 | /* | |
430 | * struct synaptics_rmi4_data - rmi4 device instance data | |
431 | * @i2c_client: pointer to associated i2c client | |
432 | * @input_dev: pointer to associated input device | |
433 | * @board: constant pointer to platform data | |
434 | * @rmi4_mod_info: device information | |
435 | * @regulator: pointer to associated regulator | |
436 | * @rmi4_io_ctrl_mutex: mutex for i2c i/o control | |
437 | * @det_work: work thread instance for expansion function detection | |
438 | * @det_workqueue: pointer to work queue for work thread instance | |
439 | * @early_suspend: instance to support early suspend power management | |
440 | * @current_page: current page in sensor to acess | |
441 | * @button_0d_enabled: flag for 0d button support | |
442 | * @full_pm_cycle: flag for full power management cycle in early suspend stage | |
443 | * @num_of_intr_regs: number of interrupt registers | |
444 | * @f01_query_base_addr: query base address for f01 | |
445 | * @f01_cmd_base_addr: command base address for f01 | |
446 | * @f01_ctrl_base_addr: control base address for f01 | |
447 | * @f01_data_base_addr: data base address for f01 | |
448 | * @irq: attention interrupt | |
449 | * @sensor_max_x: sensor maximum x value | |
450 | * @sensor_max_y: sensor maximum y value | |
451 | * @irq_enabled: flag for indicating interrupt enable status | |
452 | * @touch_stopped: flag to stop interrupt thread processing | |
453 | * @fingers_on_2d: flag to indicate presence of fingers in 2d area | |
454 | * @sensor_sleep: flag to indicate sleep state of sensor | |
455 | * @wait: wait queue for touch data polling in interrupt thread | |
456 | * @i2c_read: pointer to i2c read function | |
457 | * @i2c_write: pointer to i2c write function | |
458 | * @irq_enable: pointer to irq enable function | |
459 | */ | |
460 | struct synaptics_rmi4_data { | |
461 | struct i2c_client *i2c_client; | |
462 | struct input_dev *input_dev; | |
463 | const struct synaptics_dsx_platform_data *board; | |
464 | struct synaptics_rmi4_device_info rmi4_mod_info; | |
465 | struct regulator *regulator; | |
466 | struct mutex rmi4_io_ctrl_mutex; | |
467 | // struct delayed_work det_work; | |
468 | struct work_struct work; | |
469 | struct workqueue_struct *det_workqueue; | |
470 | struct workqueue_struct *workqueue; | |
471 | //struct early_suspend early_suspend; | |
472 | unsigned char current_page; | |
473 | unsigned char button_0d_enabled; | |
474 | unsigned char full_pm_cycle; | |
475 | unsigned char num_of_rx; | |
476 | unsigned char num_of_tx; | |
477 | unsigned char intr_mask[MAX_INTR_REGISTERS]; | |
478 | unsigned short num_of_intr_regs; | |
479 | unsigned short f01_query_base_addr; | |
480 | unsigned short f01_cmd_base_addr; | |
481 | unsigned short f01_ctrl_base_addr; | |
482 | unsigned short f01_data_base_addr; | |
483 | int irq; | |
484 | int sensor_max_x; | |
485 | int sensor_max_y; | |
486 | bool irq_enabled; | |
487 | bool touch_stopped; | |
488 | bool fingers_on_2d; | |
489 | bool sensor_sleep; | |
490 | wait_queue_head_t wait; | |
491 | int (*i2c_read)(struct synaptics_rmi4_data *pdata, unsigned short addr, | |
492 | unsigned char *data, unsigned short length); | |
493 | int (*i2c_write)(struct synaptics_rmi4_data *pdata, unsigned short addr, | |
494 | unsigned char *data, unsigned short length); | |
495 | int (*irq_enable)(struct synaptics_rmi4_data *rmi4_data, bool enable); | |
496 | int (*reset_device)(struct synaptics_rmi4_data *rmi4_data); | |
497 | }; | |
498 | ||
499 | ||
500 | ||
501 | struct synaptics_rmi4_exp_fn_ptr { | |
502 | int (*read)(struct synaptics_rmi4_data *rmi4_data, unsigned short addr, | |
503 | unsigned char *data, unsigned short length); | |
504 | int (*write)(struct synaptics_rmi4_data *rmi4_data, unsigned short addr, | |
505 | unsigned char *data, unsigned short length); | |
506 | int (*enable)(struct synaptics_rmi4_data *rmi4_data, bool enable); | |
507 | }; | |
508 | ||
509 | void synaptics_rmi4_new_function(enum exp_fn fn_type, bool insert, | |
510 | int (*func_init)(struct i2c_client *client), | |
511 | void (*func_remove)(struct i2c_client *client), | |
512 | void (*func_attn)(struct i2c_client *client, | |
513 | unsigned char intr_mask)); | |
514 | ||
515 | static inline ssize_t synaptics_rmi4_show_error(struct device *dev, | |
516 | struct device_attribute *attr, char *buf) | |
517 | { | |
518 | #if 0 | |
519 | dev_warn(dev, "%s Attempted to read from write-only attribute %s\n", | |
520 | __func__, attr->attr.name); | |
521 | #endif | |
522 | return -EPERM; | |
523 | } | |
524 | ||
525 | static inline ssize_t synaptics_rmi4_store_error(struct device *dev, | |
526 | struct device_attribute *attr, const char *buf, size_t count) | |
527 | { | |
528 | #if 0 | |
529 | dev_warn(dev, "%s Attempted to write to read-only attribute %s\n", | |
530 | __func__, attr->attr.name); | |
531 | #endif | |
532 | return -EPERM; | |
533 | } | |
534 | ||
535 | static inline void batohs(unsigned short *dest, unsigned char *src) | |
536 | { | |
537 | *dest = src[1] * 0x100 + src[0]; | |
538 | } | |
539 | ||
540 | static inline void hstoba(unsigned char *dest, unsigned short src) | |
541 | { | |
542 | dest[0] = src % 0x100; | |
543 | dest[1] = src / 0x100; | |
544 | } | |
545 | ||
546 | #endif |